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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/api/next_api_changes/2017-12-12-JMK.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
`.Axes.hist2d` now uses `~.Axes.pcolormesh` instead of `~.Axes.pcolorfast`
--------------------------------------------------------------------------

`.Axes.hist2d` now uses `~.Axes.pcolormesh` instead of `~.Axes.pcolorfast`,
which will improve the handling of log-axes. Note that the
returned *image* now is of type `~.matplotlib.collections.QuadMesh`
instead of `~.matplotlib.image.AxesImage`.
4 changes: 2 additions & 2 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6505,7 +6505,7 @@ def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
The bin edges along the x axis.
yedges : 1D array
The bin edges along the y axis.
image : AxesImage
image : `~.matplotlib.collections.QuadMesh`

Other Parameters
----------------
Expand Down Expand Up @@ -6545,7 +6545,7 @@ def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
if cmax is not None:
h[h > cmax] = None

pc = self.pcolorfast(xedges, yedges, h.T, **kwargs)
pc = self.pcolormesh(xedges, yedges, h.T, **kwargs)
self.set_xlim(xedges[0], xedges[-1])
self.set_ylim(yedges[0], yedges[-1])

Expand Down
Binary file modified lib/matplotlib/tests/baseline_images/test_axes/hist2d.pdf
Binary file not shown.
Binary file modified lib/matplotlib/tests/baseline_images/test_axes/hist2d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
421 changes: 54 additions & 367 deletions lib/matplotlib/tests/baseline_images/test_axes/hist2d.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
459 changes: 54 additions & 405 deletions lib/matplotlib/tests/baseline_images/test_axes/hist2d_transpose.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 7 additions & 5 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1646,24 +1646,26 @@ def test_contour_colorbar():
cbar.add_lines(cs2, erase=False)


@image_comparison(baseline_images=['hist2d', 'hist2d'])
@image_comparison(baseline_images=['hist2d', 'hist2d'],
remove_text=True, style='mpl20')
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?


# Reuse testcase from above for a labeled data test
data = {"x": x, "y": y}
fig = plt.figure()
ax = fig.add_subplot(111)
ax.hist2d("x", "y", bins=10, data=data)
ax.hist2d("x", "y", bins=10, data=data, rasterized=True)


@image_comparison(baseline_images=['hist2d_transpose'])
@image_comparison(baseline_images=['hist2d_transpose'],
remove_text=True, style='mpl20')
def test_hist2d_transpose():
np.random.seed(0)
# make sure the output from np.histogram is transposed before
Expand All @@ -1672,7 +1674,7 @@ def test_hist2d_transpose():
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)


@image_comparison(baseline_images=['scatter', 'scatter'])
Expand Down
6 changes: 0 additions & 6 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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....

im = plt.hist2d([1, 2, 3], [3, 5, 6],
bins=[[0, 3, 7], [1, 2, 3]])[-1]
assert im.get_extent() == (0, 7, 1, 3)


def test_minimized_rasterized():
# This ensures that the rasterized content in the colorbars is
# only as thick as the colorbar, and doesn't extend to other parts
Expand Down