Home > Back-end >  About histogram plot in matplotlib in Python
About histogram plot in matplotlib in Python

Time:10-31

I am trying to plot a histogram of a list using density=True option in the histogram method in matplotlib. The code is

import matplotlib.pyplot as plt

test=[1,2,3,1,1,3,2,1]
bins=100
plt.hist(test,bins,density=True)
plt.show() 

I want a probability density plot. For the above example, the probability density of number 1 should be 0.5(4/8), of number 2 should be 0.25(2/8) and that of number 3 should be 0.25(2/8). But the code above does not give me the desired plot. The output with the above code is density for number 1 is 2.5, for numbers 2 and 3 are 1.25.

How can I get a probability density plot either using histogram in matplotlib or another plotting tool in python? Thanks.

CodePudding user response:

According to the documentation of enter image description here

  • Related