[Matplotlib] Ploting an exponential distribution frequency curve

John Ladasky john_ladasky at sbcglobal.net
Sun Apr 26 07:08:09 CEST 2015


On Saturday, April 25, 2015 at 4:16:04 PM UTC-7, Mario Figueiredo wrote:
[snip]
> This works as intended. But plots a jagged curve due to the small
> discrepancies normal of a random number generation.
> 
> Other than replacing the random module with the probability density
> function for the exponential distribution, do you have a suggestion of
> how I could smooth the curve?

Since you have a finite data set which only approximates the exponential distribution, a visual representation which connects the dots with line segments will definitely emphasize the noise in your data.

Matplotlib.pyplot has another useful function, scatter().  Scatter does not draw lines between adjacent values.  Start there.  See how your eye likes that.

If you really want to show a curve, and you do not want to calculate the limiting (infinite data samples) exponential variate on which your sample would eventually converge, you could construct moving averages using a sliding-window sample of the points (ordered by x value, of course) and then connect those averages.




More information about the Python-list mailing list