user1778543
user1778543

Reputation: 167

How do you plot relative frequency in python

I am looking to plot the relative frequency of a bunch of numbers in Python. I need to use the hist function, I have looked elsewhere on this site but I haven't found anything.

I am doing the following

x = array ([6.36,6.34,6.36,6.73,7.36,6.73])
hist (x)

When I do this I get a plot of just frequency, how do I make it relative frequency?

Upvotes: 2

Views: 8671

Answers (1)

tacaswell
tacaswell

Reputation: 87376

hist(x, density=True)

The keyword density will plot the data such that the integral is 1 (doc). For old versions of Matplotlib you will need to use normed instead.

If you want the sum (not the integral) to be one

x = randn(30)
count,bins = np.histogram(x)
bar(bins[:-1],count,width = np.mean(np.diff(bins)))

Upvotes: 3

Related Questions