0

I am using the following script to plot the probability density curve but it only shows the histogram as a function of density. May someone suggest to me how can I get the probability density curve.

from matplotlib import pyplot
from numpy.random import normal
from numpy import mean[enter image description here][1]
from numpy import std
from scipy.stats import norm
data = pd.read_csv("a.txt", sep='\t',header=None)
sample = data[0]
sample_mean = mean(sample)
sample_std = std(sample)
dist = norm(sample_mean, sample_std)
values = [value for value in range(0, 1)]
probabilities = [dist.pdf(value) for value in values]
pyplot.hist(sample, bins=10, density=True)
plt.xlim(0,1)
pyplot.plot(values, probabilities, 'r')
pyplot.show()
Progman
  • 16,827
  • 6
  • 33
  • 48
Adnan
  • 67
  • 6

2 Answers2

0

If you are using R, this is a good site for plots https://www.r-graph-gallery.com/, you can check it. Especially the part of ggplots is quite useful.

If you prefer python this is also a useful site https://towardsdatascience.com/histograms-and-density-plots-in-python-f6bda88f5ac0.

I hope these helps you.

0

I found this useful and I hope you do too https://www.datacamp.com/community/tutorials/probability-distributions-python

Azeem Lodhi
  • 53
  • 11