Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 1 commit into from
Apr 10, 2018

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Dec 12, 2017

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

  • Code is PEP 8 compliant
  • Documentation is sphinx and numpydoc compliant
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@jklymak jklymak changed the title MNT: hist 2d now uses pcolormesh instead of pcolorfast MNT: hist2d now uses pcolormesh instead of pcolorfast Dec 12, 2017
@jklymak
Copy link
Member Author

jklymak commented Dec 12, 2017

Originally by @jankoeh...

@jklymak
Copy link
Member Author

jklymak commented Dec 12, 2017

Difference between pcolormesh and pcolorfast is that pcolormesh has the anti-aliasing artifacts in PDF at the boundaries, whereas pcolorfast does not.

In the conversation of #4625 folks seemed in favour of using pcolormesh, but I never quite saw the rationale. Happy to close this PR if there is no strong rationale.

@tacaswell tacaswell added this to the v2.2 milestone Dec 13, 2017
`~.hist2d` now uses `~.pcolormesh` instead of `~.pcolorfast`
------------------------------------------------------------

`~.hist2d` now uses `~.pcolormesh` instead of `~.pcolorfast`.
Copy link
Contributor

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?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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.

@jklymak jklymak modified the milestones: v2.2, v3.0 Jan 10, 2018
Copy link
Member

@dstansby dstansby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be keen to see this go in, with the expansion on the API changes that @anntzer and @efiring have suggested.

@jklymak
Copy link
Member Author

jklymak commented Apr 9, 2018

@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....

@dstansby
Copy link
Member

dstansby commented Apr 9, 2018

I'm happy to push stuff to your branch if you don't mind?

@jklymak
Copy link
Member Author

jklymak commented Apr 9, 2018

I don’t mind at all. But don’t feel obliged - I will get to it the next couple of days...

@jklymak jklymak force-pushed the mnt-hist2d-pcolor branch 3 times, most recently from 37de055 to 2a936b2 Compare April 9, 2018 19:34
@@ -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():
Copy link
Member Author

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....

@jklymak jklymak force-pushed the mnt-hist2d-pcolor branch 2 times, most recently from 8a1f77a to 0c40aac Compare April 9, 2018 21:36
Copy link
Member

@efiring efiring left a 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.

@jklymak jklymak force-pushed the mnt-hist2d-pcolor branch from 0c40aac to 6f9251c Compare April 9, 2018 22:21
@efiring
Copy link
Member

efiring commented Apr 9, 2018

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.

@jklymak
Copy link
Member Author

jklymak commented Apr 10, 2018

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)
Copy link
Member

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?

@jklymak
Copy link
Member Author

jklymak commented Apr 10, 2018

Otherwise you get lines in the PDF output.

@dstansby dstansby merged commit fb84253 into matplotlib:master Apr 10, 2018
@dstansby
Copy link
Member

🎉 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!)

@jklymak
Copy link
Member Author

jklymak commented Apr 10, 2018

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

@jklymak jklymak deleted the mnt-hist2d-pcolor branch April 10, 2018 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants