Revision: 5407
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5407&view=rev
Author:   jdh2358
Date:     2008-06-05 15:23:50 -0700 (Thu, 05 Jun 2008)

Log Message:
-----------
added api histogram demo which comments on the new bins return value

Added Paths:
-----------
    trunk/matplotlib/examples/api/histogram_demo.py

Added: trunk/matplotlib/examples/api/histogram_demo.py
===================================================================
--- trunk/matplotlib/examples/api/histogram_demo.py                             
(rev 0)
+++ trunk/matplotlib/examples/api/histogram_demo.py     2008-06-05 22:23:50 UTC 
(rev 5407)
@@ -0,0 +1,35 @@
+"""
+Make a histogram of normally distributed random numbers and plot the
+analytic PDF over it
+"""
+import numpy as np
+import matplotlib.pyplot as plt
+import matplotlib.mlab as mlab
+
+mu, sigma = 100, 15
+x = mu + sigma * np.random.randn(10000)
+
+fig = plt.figure()
+ax = fig.add_subplot(111)
+
+# the histogram of the data
+n, bins, patches = ax.hist(x, 50, normed=1, facecolor='green', alpha=0.75)
+
+# hist uses np.histogram under the hood to create 'n' and 'bins'.
+# np.histogram returns the bin edges, so there will be 50 probability
+# density values in n, 51 bin edges in bins and 50 patches.  To get
+# everything lined up, we'll compute the bin centers
+bincenters = 0.5*(bins[1:]+bins[:-1])
+# add a 'best fit' line for the normal PDF
+y = mlab.normpdf( bincenters, mu, sigma)
+l = ax.plot(bincenters, y, 'r--', linewidth=1)
+
+ax.set_xlabel('Smarts')
+ax.set_ylabel('Probability')
+#ax.set_title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$')
+ax.set_xlim(40, 160)
+ax.set_ylim(0, 0.03)
+ax.grid(True)
+
+#fig.savefig('histogram_demo',dpi=72)
+plt.show()


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to