-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
MNT: hist2d now uses pcolormesh instead of pcolorfast #9987
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
Conversation
Originally by @jankoeh... |
Difference between In the conversation of #4625 folks seemed in favour of using |
`~.hist2d` now uses `~.pcolormesh` instead of `~.pcolorfast` | ||
------------------------------------------------------------ | ||
|
||
`~.hist2d` now uses `~.pcolormesh` instead of `~.pcolorfast`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explicitly mention that this changes the return type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And that the rationale is to provide support for log axes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But `AxesImage now behaves correctly on log scales.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so we don't need this anymore? I didn't check recently that log scales now work.
OTOH, Somewhat prefer pcolormesh, but thats just out of familiarity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dstansby OK, great. I'll fix it up ASAP; it wasn't super high on my priority list of things to harass people about, but happy to shepherd it through if there is a constituency.... |
I'm happy to push stuff to your branch if you don't mind? |
I don’t mind at all. But don’t feel obliged - I will get to it the next couple of days... |
37de055
to
2a936b2
Compare
@@ -586,12 +586,6 @@ def test_pcolorimage_setdata(): | |||
assert im._A[0, 0] == im._Ax[0] == im._Ay[0] == 0, 'value changed' | |||
|
|||
|
|||
def test_pcolorimage_extent(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this was a bad thing to do....
8a1f77a
to
0c40aac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine once it passes the tests.
0c40aac
to
6f9251c
Compare
If the bins are not regularly spaced, the call to pcolorfast will return a PcolorImage, not an AxesImage, and PcolorImage does not support log scales. There is no reason it couldn't. |
Ping @dstansby this is all done. Not sure if @tacaswell is OK w/ the change, but I think @efiring makes a compelling argument.... |
def test_hist2d(): | ||
np.random.seed(0) | ||
# make it not symmetric in case we switch x and y axis | ||
x = np.random.randn(100)*2+5 | ||
y = np.random.randn(100)-2 | ||
fig = plt.figure() | ||
ax = fig.add_subplot(111) | ||
ax.hist2d(x, y, bins=10) | ||
ax.hist2d(x, y, bins=10, rasterized=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the rasterized=True
argument?
Otherwise you get lines in the PDF output. |
🎉 thanks for this! (I'm plotting so many 2D histograms in log-space at the moment, so this will save me a lot of hassle!) |
NP. Are we OK w/ the rasterized=True argument? it doesnt' really matter, except it gets rid of the anti-aliasing artifact pcolormesh has for most PDF viewers. https://github.com/jklymak/contourfIssues |
PR Summary
This is a redo of #4625 which simply changes hist2d to use pcolormesh instead of pcolorfast.
The reason for doing so is to be able to handle log scales, which pcolormesh does but pcolorfast does not.
PR Checklist