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

Skip to content

Commit 8568ccb

Browse files
committed
Fixed histogram autoscaling bug when bins or range are given explicitly
svn path=/trunk/matplotlib/; revision=6459
1 parent 4585a09 commit 8568ccb

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2008-12-01 Fixed histogram autoscaling bug when bins or range are given
2+
explicitly (fixes Debian bug 503148) - MM
3+
14
2008-11-25 Added rcParam axes.unicode_minus which allows plain hypen
25
for minus when False - JDH
36

lib/matplotlib/axes.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6510,6 +6510,9 @@ def hist(self, x, bins=10, range=None, normed=False, cumulative=False,
65106510
"""
65116511
if not self._hold: self.cla()
65126512

6513+
# NOTE: the range keyword overwrites the built-in func range !!!
6514+
# needs to be fixed in with numpy !!!
6515+
65136516
if kwargs.get('width') is not None:
65146517
raise DeprecationWarning(
65156518
'hist now uses the rwidth to give relative width '
@@ -6531,6 +6534,10 @@ def hist(self, x, bins=10, range=None, normed=False, cumulative=False,
65316534
tx.append( np.array(x[i]) )
65326535
x = tx
65336536

6537+
# Check whether bins or range are given explicitly. In that
6538+
# case do not autoscale axes.
6539+
binsgiven = (cbook.iterable(bins) or range != None)
6540+
65346541
n = []
65356542
for i in xrange(len(x)):
65366543
# this will automatically overwrite bins,
@@ -6541,9 +6548,8 @@ def hist(self, x, bins=10, range=None, normed=False, cumulative=False,
65416548

65426549
if cumulative:
65436550
slc = slice(None)
6544-
if cbook.is_numlike(cumulative):
6545-
if cumulative < 0:
6546-
slc = slice(None,None,-1)
6551+
if cbook.is_numlike(cumulative) and cumulative < 0:
6552+
slc = slice(None,None,-1)
65476553

65486554
if normed:
65496555
n = [(m * np.diff(bins))[slc].cumsum()[slc] for m in n]
@@ -6675,6 +6681,16 @@ def hist(self, x, bins=10, range=None, normed=False, cumulative=False,
66756681
p.set_label(label)
66766682
label = '_nolegend_'
66776683

6684+
if binsgiven:
6685+
self.set_autoscale_on(False)
6686+
if orientation == 'vertical':
6687+
self.autoscale_view(scalex=False, scaley=True)
6688+
XL = self.xaxis.get_major_locator().view_limits(bins[0], bins[-1])
6689+
self.set_xbound(XL)
6690+
else:
6691+
self.autoscale_view(scalex=True, scaley=False)
6692+
YL = self.yaxis.get_major_locator().view_limits(bins[0], bins[-1])
6693+
self.set_ybound(YL)
66786694

66796695
if len(n)==1:
66806696
return n[0], bins, cbook.silent_list('Patch', patches[0])

0 commit comments

Comments
 (0)