Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 21e579d

Browse files
committed
do not rely on equalwidth bin assumption for cumhist; trapz doesn't work correctly with new histogram semantic
svn path=/trunk/matplotlib/; revision=5148
1 parent a782092 commit 21e579d

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

lib/matplotlib/axes.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5420,9 +5420,9 @@ def hist(self, x, bins=10, normed=False, cumulative=False,
54205420
bottom=None, histtype='bar', align='edge',
54215421
orientation='vertical', width=None, log=False, **kwargs):
54225422
"""
5423-
HIST(x, bins=10, normed=False, bottom=None, histtype='bar',
5424-
align='edge', orientation='vertical', width=None,
5425-
log=False, **kwargs)
5423+
HIST(x, bins=10, normed=False, cumulative=False,
5424+
bottom=None, histtype='bar', align='edge',
5425+
orientation='vertical', width=None, log=False, **kwargs)
54265426
54275427
Compute the histogram of x. bins is either an integer number of
54285428
bins or a sequence giving the bins. x are the data to be binned.
@@ -5437,13 +5437,13 @@ def hist(self, x, bins=10, normed=False, cumulative=False,
54375437
54385438
# trapezoidal integration of the probability density function
54395439
pdf, bins, patches = ax.hist(...)
5440-
print np.trapz(pdf, bins)
5440+
print np.sum(pdf * np.diff(bins))
54415441
5442-
If cumulative is True then histogram is computed where each bin
5442+
If cumulative is True then a histogram is computed where each bin
54435443
gives the counts in that bin plus all bins for smaller values.
54445444
The last bins gives the total number of datapoints. If normed is
54455445
also True then the histogram is normalized such that the last bin
5446-
equals one (assuming equally spaced bins).
5446+
equals one.
54475447
54485448
histtype = 'bar' | 'step'. The type of histogram to draw.
54495449
'bar' is a traditional bar-type histogram, 'step' generates
@@ -5469,10 +5469,10 @@ def hist(self, x, bins=10, normed=False, cumulative=False,
54695469
normed=bool(normed), new=True)
54705470

54715471
if cumulative:
5472-
n = n.cumsum()
54735472
if normed:
5474-
# normalize to 1
5475-
n *= (bins[1]-bins[0])
5473+
n = (n * np.diff(bins)).cumsum()
5474+
else:
5475+
n = n.cumsum()
54765476

54775477
if histtype == 'bar':
54785478
if width is None:

0 commit comments

Comments
 (0)