diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index a41160789fbd..2cc1646fb285 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -5909,7 +5909,9 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, logbase = self.yaxis._scale.base # Setting a minimum of 0 results in problems for log plots - if normed or weights is not None: + if np.min(bottom) > 0: + minimum = np.min(bottom) + elif normed or weights is not None: # For normed data, set to log base * minimum data value # (gives 1 full tick-label unit for the lowest filled bin) ndata = np.array(n) diff --git a/lib/matplotlib/tests/baseline_images/test_axes/hist_step_log_bottom.png b/lib/matplotlib/tests/baseline_images/test_axes/hist_step_log_bottom.png new file mode 100644 index 000000000000..48b4ced7f327 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_axes/hist_step_log_bottom.png differ diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 299e9e0aa21a..ac297789a85e 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -1082,6 +1082,30 @@ def test_hist_steplog(): plt.hist(data_big, 100, histtype='stepfilled', log=True, orientation='horizontal') +@image_comparison(baseline_images=['hist_step_log_bottom'], + remove_text=True, extensions=['png']) +def test_hist_step_log_bottom(): + # check that bottom doesn't get overwritten by the 'minimum' on a + # log scale histogram (https://github.com/matplotlib/matplotlib/pull/4608) + np.random.seed(0) + data = np.random.standard_normal(2000) + fig = plt.figure() + ax = fig.add_subplot(111) + # normal hist (should clip minimum to 1/base) + ax.hist(data, bins=10, log=True, histtype='stepfilled', + alpha=0.5, color='b') + # manual bottom < 1/base (previously buggy, see #4608) + ax.hist(data, bins=10, log=True, histtype='stepfilled', + alpha=0.5, color='g', bottom=1e-2) + # manual bottom > 1/base + ax.hist(data, bins=10, log=True, histtype='stepfilled', + alpha=0.5, color='r', bottom=0.5) + # array bottom with some less than 1/base (should clip to 1/base) + ax.hist(data, bins=10, log=True, histtype='stepfilled', + alpha=0.5, color='y', bottom=np.arange(10)) + ax.set_ylim(9e-3, 1e3) + + def contour_dat(): x = np.linspace(-3, 5, 150) y = np.linspace(-3, 5, 120)