Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo
Close
From: Simson Garfinkel <simsong@ac...>  20070317 22:13:06

Hi. I haven't been active for a while, but now I have another paper that I need to get out... Anyway, I need to draw a cumulative distribution function, as the reviewers of my last paper really nailed me to the wall for including histograms instead of CDFs. Is there any way to plot a CDF with matplotlib? 
From: John Hunter <jdh2358@gm...>  20070318 16:41:29

On 3/17/07, Simson Garfinkel <simsong@...> wrote: > Hi. I haven't been active for a while, but now I have another paper > that I need to get out... Glad to have you back... > Anyway, I need to draw a cumulative distribution function, as the > reviewers of my last paper really nailed me to the wall for including > histograms instead of CDFs. Is there any way to plot a CDF with > matplotlib? For analytic cdfs, see scipy.stats. I assume you need an empirical cdf. You can use matplotlib.mlab.hist to compute the empirical pdf (use normed=True to return a PDF rather than a frequency count). Then use numpy.cumsum to do the cumulative sum of the pdf, multiplying by the binsize so it approximates the integral. import matplotlib.mlab from pylab import figure, show, nx x = nx.mlab.randn(10000) p,bins = matplotlib.mlab.hist(x, 50, normed=True) db = bins[1]bins[0] cdf = nx.cumsum(p*db) fig = figure() ax = fig.add_subplot(111) ax.bar(bins, cdf, width=0.8*db) show() 
From: Simson Garfinkel <simsong@ac...>  20070318 20:46:45

On Mar 18, 2007, at 12:41 PM, John Hunter wrote: > On 3/17/07, Simson Garfinkel <simsong@...> wrote: >> Hi. I haven't been active for a while, but now I have another paper >> that I need to get out... > > Glad to have you back... Thanks. I've taken a new job, moved to california, and have been flying between the two coasts every week. It doesn't leave much time for mailing lists... > >> Anyway, I need to draw a cumulative distribution function, as the >> reviewers of my last paper really nailed me to the wall for including >> histograms instead of CDFs. Is there any way to plot a CDF with >> matplotlib? > > For analytic cdfs, see scipy.stats. I assume you need an empirical > cdf. You can use matplotlib.mlab.hist to compute the empirical pdf > (use normed=True to return a PDF rather than a frequency count). Then > use numpy.cumsum to do the cumulative sum of the pdf, multiplying by > the binsize so it approximates the integral. > > import matplotlib.mlab > from pylab import figure, show, nx > > x = nx.mlab.randn(10000) > p,bins = matplotlib.mlab.hist(x, 50, normed=True) > db = bins[1]bins[0] > cdf = nx.cumsum(p*db) > > fig = figure() > ax = fig.add_subplot(111) > ax.bar(bins, cdf, width=0.8*db) > show() > Thanks! I'll try it out and see what happens. 
From: Simson Garfinkel <simsong@ac...>  20070321 02:00:18

Thanks for the information. Unfortunately, this CDF doesn't look like the CDF that we see in other published papers. I'm not sure what they are done with... But they have a thin line that shows the integral of all measurements, rather than a bar graph. The problem with a bar graph is that different bin widths give different results. GNU Plot seems to do a decent job, as can e seen at http:// chem.skku.ac.kr/~wkpark/tutor/gnuplot/gpdocs/prob.htm. But there should be a way to do this nicely with matplotlib, right? On Mar 18, 2007, at 12:41 PM, John Hunter wrote: > On 3/17/07, Simson Garfinkel <simsong@...> wrote: >> Hi. I haven't been active for a while, but now I have another paper >> that I need to get out... > > Glad to have you back... > >> Anyway, I need to draw a cumulative distribution function, as the >> reviewers of my last paper really nailed me to the wall for including >> histograms instead of CDFs. Is there any way to plot a CDF with >> matplotlib? > > For analytic cdfs, see scipy.stats. I assume you need an empirical > cdf. You can use matplotlib.mlab.hist to compute the empirical pdf > (use normed=True to return a PDF rather than a frequency count). Then > use numpy.cumsum to do the cumulative sum of the pdf, multiplying by > the binsize so it approximates the integral. > > import matplotlib.mlab > from pylab import figure, show, nx > > x = nx.mlab.randn(10000) > p,bins = matplotlib.mlab.hist(x, 50, normed=True) > db = bins[1]bins[0] > cdf = nx.cumsum(p*db) > > fig = figure() > ax = fig.add_subplot(111) > ax.bar(bins, cdf, width=0.8*db) > show() > 
From: John Hunter <jdh2358@gm...>  20070321 02:58:32

On 3/20/07, Simson Garfinkel <simsong@...> wrote: > Thanks for the information. Unfortunately, this CDF doesn't look like > the CDF that we see in other published papers. I'm not sure what they > are done with... But they have a thin line that shows the integral > of all measurements, rather than a bar graph. The problem with a bar > graph is that different bin widths give different results. > > GNU Plot seems to do a decent job, as can e seen at http:// > chem.skku.ac.kr/~wkpark/tutor/gnuplot/gpdocs/prob.htm. But there > should be a way to do this nicely with matplotlib, right? Just replace ax.bar(bins, p) with ax.plot(bins, b) in the example code I posted previously... JDH 
From: Werner Hoch <werner.ho@gm...>  20070321 07:55:35

Hi Simson, On Wednesday 21 March 2007 02:59, Simson Garfinkel wrote: > Thanks for the information. Unfortunately, this CDF doesn't look like > the CDF that we see in other published papers. I'm not sure what they > are done with... But they have a thin line that shows the integral > of all measurements, rather than a bar graph. The problem with a bar > graph is that different bin widths give different results. > > GNU Plot seems to do a decent job, as can e seen at http:// > chem.skku.ac.kr/~wkpark/tutor/gnuplot/gpdocs/prob.htm. But there > should be a way to do this nicely with matplotlib, right? Try this one: x = sin(arange(0,100,0.1)) ## your function ## plot the sorted value of your function against ## a linear vektor from 0 to 1 with the same length plot(sort(x), arange(len(x))/float(len(x))) Regrads Werner 