Skip to content

Commit 2dc2825

Browse files
committed
Merge pull request matplotlib#1684 from dmcdougall/fix_loghist
Fix hist for log=True and histtype='step'
2 parents f2712d5 + d1c9bb4 commit 2dc2825

File tree

5 files changed

+2118
-8
lines changed

5 files changed

+2118
-8
lines changed

lib/matplotlib/axes.py

+22-8
Original file line numberDiff line numberDiff line change
@@ -8184,19 +8184,33 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
81848184

81858185
x[0::2], x[1::2] = bins, bins
81868186

8187-
minimum = np.min(n)
8188-
8189-
if align == 'left' or align == 'center':
8190-
x -= 0.5*(bins[1]-bins[0])
8191-
elif align == 'right':
8192-
x += 0.5*(bins[1]-bins[0])
8193-
81948187
if log:
8195-
y[0],y[-1] = minimum, minimum
81968188
if orientation == 'horizontal':
81978189
self.set_xscale('log')
8190+
logbase = self.xaxis._scale.base
81988191
else: # orientation == 'vertical'
81998192
self.set_yscale('log')
8193+
logbase = self.yaxis._scale.base
8194+
8195+
# Setting a minimum of 0 results in problems for log plots
8196+
if normed:
8197+
# For normed data, set to log base * minimum data value
8198+
# (gives 1 full tick-label unit for the lowest filled bin)
8199+
ndata = np.array(n)
8200+
minimum = (np.min(ndata[ndata>0])) / logbase
8201+
else:
8202+
# For non-normed data, set the min to log base, again so that
8203+
# there is 1 full tick-label unit for the lowest bin
8204+
minimum = 1.0 / logbase
8205+
8206+
y[0], y[-1] = minimum, minimum
8207+
else:
8208+
minimum = np.min(bins)
8209+
8210+
if align == 'left' or align == 'center':
8211+
x -= 0.5*(bins[1]-bins[0])
8212+
elif align == 'right':
8213+
x += 0.5*(bins[1]-bins[0])
82008214

82018215
# If fill kwarg is set, it will be passed to the patch collection,
82028216
# overriding this
Binary file not shown.
Loading

0 commit comments

Comments
 (0)