From: <jd...@us...> - 2007-10-26 20:16:08
|
Revision: 4029 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4029&view=rev Author: jdh2358 Date: 2007-10-26 13:15:51 -0700 (Fri, 26 Oct 2007) Log Message: ----------- added stats distributions examples Modified Paths: -------------- trunk/py4science/examples/stats_descriptives.py trunk/py4science/examples/stats_distributions.py Modified: trunk/py4science/examples/stats_descriptives.py =================================================================== --- trunk/py4science/examples/stats_descriptives.py 2007-10-26 20:15:42 UTC (rev 4028) +++ trunk/py4science/examples/stats_descriptives.py 2007-10-26 20:15:51 UTC (rev 4029) @@ -76,21 +76,27 @@ c = C() N = 5 fig = c.fig = figfunc() + fig.subplots_adjust(hspace=0.3) ax = c.ax1 = fig.add_subplot(N,1,1) c.plot = ax.plot(data, fmt) + ax.set_ylabel('data') ax = c.ax2 = fig.add_subplot(N,1,2) c.hist = ax.hist(data, bins) + ax.set_ylabel('hist') - ax = c.ax3 = fig.add_subplot(N,1,3) - c.acorr = ax.acorr(data, detrend=detrend, usevlines=True, maxlags=maxlags) + c.acorr = ax.acorr(data, detrend=detrend, usevlines=True, + maxlags=maxlags, normed=True) + ax.set_ylabel('acorr') ax = c.ax4 = fig.add_subplot(N,1,4) c.psd = ax.psd(data, Fs=Fs, detrend=detrend) + ax.set_ylabel('psd') ax = c.ax5 = fig.add_subplot(N,1,5) c.specgtram = ax.specgram(data, Fs=Fs, detrend=detrend) + ax.set_ylabel('specgram') return c @@ -111,6 +117,9 @@ desc = Descriptives(data) print desc - c = desc.plots(pylab.figure, Fs=12, fmt='-o') + c = desc.plots(pylab.figure, Fs=12, fmt='-') c.ax1.set_title(fname) + + c.fig.savefig('stats_descriptives.png', dpi=150) + c.fig.savefig('stats_descriptives.eps') pylab.show() Modified: trunk/py4science/examples/stats_distributions.py =================================================================== --- trunk/py4science/examples/stats_distributions.py 2007-10-26 20:15:42 UTC (rev 4028) +++ trunk/py4science/examples/stats_distributions.py 2007-10-26 20:15:51 UTC (rev 4029) @@ -35,18 +35,18 @@ # 1/lambda. Plot all three on the same graph and make a legend. # Decorate your graphs with an xlabel, ylabel and title fig = figure() -ax = fig.add_subplot(111) +ax = fig.add_subplot(311) p, bins, patches = ax.hist(wait_times, 100, normed=True) l1, = ax.plot(bins, rate*numpy.exp(-rate * bins), lw=2, color='red') l2, = ax.plot(bins, scipy.stats.expon.pdf(bins, 0, 1./rate), lw=2, ls='--', color='green') -ax.set_xlabel('waiting time') + ax.set_ylabel('PDF') -ax.set_title('waiting time density of a %dHz Poisson emitter'%rate) +ax.set_title('waiting time densities of a %dHz Poisson emitter'%rate) +ax.text(0.05, 0.9, 'one interval', transform=ax.transAxes) ax.legend((patches[0], l1, l2), ('simulated', 'analytic', 'scipy.stats.expon')) - # plot the distribution of waiting times for two events; the # distribution of waiting times for N events should equal a N-th order # gamma distribution (the exponential distribution is a 1st order @@ -54,17 +54,15 @@ # Hint: you can stride your emission times array to get every 2nd # emission wait_times2 = numpy.diff(emit_times[::2]) -fig = figure() -ax = fig.add_subplot(111) +ax = fig.add_subplot(312) p, bins, patches = ax.hist(wait_times2, 100, normed=True) l1, = ax.plot(bins, scipy.stats.gamma.pdf(bins, 2, 0, 1./rate), lw=2, ls='-', color='red') -ax.set_xlabel('2 event waiting time 2 events') + ax.set_ylabel('PDF') -ax.set_title('waiting time density of a %dHz Poisson emitter'%rate) +ax.text(0.05, 0.9, 'two intervals', transform=ax.transAxes) ax.legend((patches[0], l1), ('simulated', 'scipy.stats.gamma')) - # plot the distribution of waiting times for 10 events; again the # distribution will be a 10th order gamma distribution so plot that # along with the empirical density. The central limit thm says that @@ -81,19 +79,20 @@ mu, var = 10*expon_mean, 10*expon_var sigma = numpy.sqrt(var) wait_times10 = numpy.diff(emit_times[::10]) -fig = figure() -ax = fig.add_subplot(111) +ax = fig.add_subplot(313) p, bins, patches = ax.hist(wait_times10, 100, normed=True) l1, = ax.plot(bins, scipy.stats.gamma.pdf(bins, 10, 0, 1./rate), lw=2, ls='-', color='red') l2, = ax.plot(bins, scipy.stats.norm.pdf(bins, mu, sigma), lw=2, ls='--', color='green') -ax.set_xlabel('waiting time 10 events') +ax.set_xlabel('waiting times') ax.set_ylabel('PDF') -ax.set_title('10 event waiting time density of a %dHz Poisson emitter'%rate) +ax.text(0.1, 0.9, 'ten intervals', transform=ax.transAxes) ax.legend((patches[0], l1, l2), ('simulated', 'scipy.stats.gamma', 'normal approx')) +fig.savefig('stats_distributions.png', dpi=150) +fig.savefig('stats_distributions.eps') show() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |