I am creating a list ans
using the following code and have tried to create histogram plots of ans
using both matplotlib and seaborn using density=True
but I still don't get a probability density of the list of the values in ans
. Here is the code.
num=100000
ans=[]
T=4.5*math.pi
num_bins=50
for i in range(num):
val=0.5*np.random.chisquare(1)+np.random.exponential(1)
q=np.random.randn()
repeats=int(T/(2*q))
listofrepeats=list(itertools.repeat(val,repeats))
for val in listofrepeats:
ans.append(val)
#plt.hist(ans,bins=num_bins,normed=True)
sns.distplot(ans, hist=True, kde=False,
bins=num_bins, color = 'blue',
hist_kws={'edgecolor':'black'})
x=np.linspace(0.01,20,1000)
y=[0.5*np.exp(-0.5*n) for n in x]
plt.plot(x,y,lw=3,c='r',label='Chi sqrd with df=2')
plt.legend(loc='upper right')
plt.show()
The density plot I get is and as you can see, the density has large values. I am looking for a plotting tool wherein a probability is calculated for each bin and the probabilities sum to one. Is there such a tool? Thanks.