-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Histograms disappear with logarithmic y-axis #9288
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
Comments
One of import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
xs = np.random.normal(size=int(1e6))
fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.hist(xs, range=(-5, 5), bins=100)
ax2.hist(xs, range=(-5, 5), bins=100, log=True)
ax2.set_ylim(ymin=1)
fig.savefig('histogram.png') will behave as expected. |
Clearly my search-foo isn't good enough; thanks for the pointers @dstansby. I would have expected Thanks @tacaswell, I wasn't aware of that. In my case I need to be able to set the scale after the |
It is only hiding the points at 0, but the histogram is drawn as a bunch of rectangles (with their bottom at 0). Once the bottom points are masked out, we don't know how to draw the rectangle (with only 2 points). This is obviously not great for histograms, but it is consistent makes sense in other contexts. We may want to consider rolling this change back in 2.1.1 and think about it a bit more carefully. |
I guess that "in theory", the solution would be to attach additional information to the rectangles generated by hist, so that a log transform applied to them would use clip mode instead of mask? Looks ugly (and haven't thought about the proper way to implement this), but in truth I think this is somewhat similar to how the sticky-edges mechanism works: a single artist shouldn't get to decide how a whole axis property (in this case, whether to clip or to mask invalid values in log transforms) affects all artists. |
w/o looking at the code, I'm curious how The OP can of course bypass all this by calculating the histogram values and plotting them w/ |
Adjustment of ylim is controlled by |
- bug reports from matplotlib#9288 - bug report from matplotlib#9457 - demo of errorbars going negative
- bug reports from matplotlib#9288 - bug report from matplotlib#9457 - demo of errorbars going negative
Fixed by #9477 |
Bug report
Bug summary
Setting a logarithmic y-axis with
ax.set_yscale('log')
causes histograms to disappear from the axis. This occurs in 2.1.0 but not in 2.0.2.Code for reproduction
Actual outcome
With 2.1.0:
Expected outcome
I expect to see a logarithm y-axis and the histogram, but I only see the former. With 2.0.2 I see this:
The text was updated successfully, but these errors were encountered: