Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axes.hist with log=True, histtype='step...' ignores bottom kwarg #4606

Closed
duncanmmacleod opened this issue Jul 8, 2015 · 1 comment · Fixed by #4608
Closed

Axes.hist with log=True, histtype='step...' ignores bottom kwarg #4606

duncanmmacleod opened this issue Jul 8, 2015 · 1 comment · Fixed by #4608

Comments

@duncanmmacleod
Copy link
Contributor

The Axes.hist method doesn't handle the bottom kwarg properly when given log=True and histtype='step' or histtype='stepfilled'. As the example below shows, the method sets a minimum value to prevent issues with zeros on a log scale, but that supercedes a non-zero bottom kwarg:

import numpy
from matplotlib import pyplot
fig = pyplot.figure()
ax = fig.gca()
ax.hist(numpy.random.random(1000), bins=100, log=True, bottom=1e-2, histtype='stepfilled')
ax.set_ylim(1e-2, 1e3)
ax.set_title('Bottom should be 1e-2, but instead is 1/base')

mpl-hist-bottom

I can correct the issue with the following edit:

diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py
index 4d10e86..2392a6d 100644
--- a/lib/matplotlib/axes/_axes.py
+++ b/lib/matplotlib/axes/_axes.py
@@ -5779,7 +5779,9 @@ class Axes(_AxesBase):
                     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)

which uses the bottom value to set the minimum if it's nonzero. If this is confirmed as a bug, I can open a PR.

@tacaswell
Copy link
Member

Can you please create a PR with that diff? That is the easiest way for us to review and merge the change.

duncanmmacleod added a commit to duncanmmacleod/matplotlib that referenced this issue Jul 10, 2015
- this new test checks that the `bottom` kwarg to `Axes.hist` behaves
  as expected under a variety of circumstances when
  `log=True, histtype='step{filled}' given
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants