Skip to content

Create kwarg to normalize histogram such that sum of bin values equals 1 #1567

@louist87

Description

@louist87

This StackOverflow question sums up the problem pretty well. The answer is straightforward but convoluted. This kind of functionality is widely used and requested, so it would be of great benefit for the hist function to handle it automatically.

Basically, setting the normed kwarg to a logically true value normalizes the histogram such that the integral is equal to 1. I suggest creating a new kwarg, named something like normedheight (or perhaps normedh), which implements the solution proposed in the StackOverflow post.

Here is the code, for convenience:

inp = normal(size=1000)
h = hist(inp)
bar(h[1][:-1], h[0]/float(len(inp)), diff(h[1]))  # normalized histogram

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions