0

I am trying to plot the probability distribution function of a simulation that involved the 2-dimensional kinetic distribution. My result should be an exponentially decaying function and I require it to be normalized. To obtain this, I took my list (X) and I used

`plt.hist(X, bins= 100, density= 'True')`

The graph I'm obtaining:

The graph

According to the equation EXP(-x/c), for x = 0, the y-axis should be at 1. Can someone help me, please?

rawrex
  • 4,044
  • 2
  • 8
  • 24
Jo Bi
  • 97
  • 7
  • 1
    `density=True` makes the **total area** equal to 1. The heights strongly depend on the scale of the x values. – JohanC Jun 06 '21 at 09:09

1 Answers1

0

I believe the density argument normalizes the histogram to add up to one, not to have a maximum of one.

https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hist.html

I don't think the result is wrong, is there some reason you need the normalization to be to the max instead of to the total number of counts, which probably has less variance?

claymole
  • 11
  • 4
  • Thank you so much for the response. But if I use the equation EXP(-x/c) and when x = 0, the value should be 1 right? Is it because here we are taking bins and not exact value? – Jo Bi Jun 06 '21 at 05:55
  • 1
    If you give a working example, I would play with it and might be able to give more help. Without that I am a little less confident. I agree that exp(0) == 1. But the density flag is then going to normalize the visual so that the area is one. Have you tried the histogram with density = 'False'? – claymole Jun 06 '21 at 06:05
  • Thank you so much for the response. I can share my code but it's actually a 170 line code. I did try it with density='False', but for the project, I am doing my answer required it to be normalized (the area under the curve should be 1). When I reduce my bin size by increasing the number of bins, the answer was coming close to 1 at x = 0. So I think the reason is that the value shown at x = 0 corresponds to a range of values close to x = 0. – Jo Bi Jun 07 '21 at 02:58
  • It seems like you should take a step back and think this through more slowly. Normalizing a distribution changes the height of the distribution. You distribution had a height of 1 at x=0, but then your normalized it and changed the height. You can't both normalize the area to 1 and have the height at x=0 be 1 unless you only have one bin, unless I am missing something. You have to decide which one of those is more important for you. – claymole Jun 07 '21 at 23:28