matplotlib-users

 [Matplotlib-users] Histogram without probability From: nbv4 - 2009-12-15 01:22:48 ```The histogram example in the matpolotlib gallery is just what I want, except instead of "probility" shown on the Y-axis, I want the number of items that fall into each bin to be plotted. How do I do this? Here is my code: import numpy as np import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) x = self.data ## a list, such as [12.43, 34.24, 35.56, 465.3547, ] ax.hist(x, 60, normed=1, facecolor='green', alpha=0.75) ax.set_xlabel('Totals') ax.set_ylabel('Number of Users')) ax.set_xlim(0, 2000) ax.set_ylim(0, 0.003) ax.grid(True) -- View this message in context: http://old.nabble.com/Histogram-without-probability-tp26781968p26781968.html Sent from the matplotlib - users mailing list archive at Nabble.com. ```
 Re: [Matplotlib-users] Histogram without probability From: Ryan May - 2009-12-15 02:05:50 ```On Mon, Dec 14, 2009 at 7:22 PM, nbv4 wrote: > > The histogram example in the matpolotlib gallery is just what I want, except > instead of "probility" shown on the Y-axis, I want the number of items that > fall into each bin to be plotted. How do I do this? Here is my code: > >        import numpy as np >        import matplotlib >        matplotlib.use('Agg') >        import matplotlib.pyplot as plt > >        fig = plt.figure() >        ax = fig.add_subplot(111) > >        x = self.data ## a list, such as [12.43, 34.24, 35.56, 465.3547, ] >        ax.hist(x, 60, normed=1, facecolor='green', alpha=0.75) >From the docstring for ax.hist: *normed*: If *True*, the first element of the return tuple will be the counts normalized to form a probability density, i.e., ``n/(len(x)*dbin)``. In a probability density, the integral of the histogram should be 1; you can verify that with a trapezoidal integration of the probability density function:: pdf, bins, patches = ax.hist(...) print np.sum(pdf * np.diff(bins)) So instead, pass normed=False (instead of normed=1) to the call to ax.hist. Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma ```
 Re: [Matplotlib-users] Histogram without probability From: Eric Firing - 2009-12-15 02:37:07 ```nbv4 wrote: > The histogram example in the matpolotlib gallery is just what I want, except > instead of "probility" shown on the Y-axis, I want the number of items that > fall into each bin to be plotted. How do I do this? Here is my code: > > import numpy as np > import matplotlib > matplotlib.use('Agg') > import matplotlib.pyplot as plt > > fig = plt.figure() > ax = fig.add_subplot(111) > > x = self.data ## a list, such as [12.43, 34.24, 35.56, 465.3547, ] > ax.hist(x, 60, normed=1, facecolor='green', alpha=0.75) Leave out the "normed" kwarg, or set it to False (the default). http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.hist > > ax.set_xlabel('Totals') > ax.set_ylabel('Number of Users')) > ax.set_xlim(0, 2000) > ax.set_ylim(0, 0.003) > ax.grid(True) ```