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

Skip to content

Commit fb84253

Browse files
authored
Merge pull request #9987 from jklymak/mnt-hist2d-pcolor
MNT: hist2d now uses pcolormesh instead of pcolorfast
2 parents 9ec0052 + 6f9251c commit fb84253

File tree

10 files changed

+124
-785
lines changed

10 files changed

+124
-785
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
`.Axes.hist2d` now uses `~.Axes.pcolormesh` instead of `~.Axes.pcolorfast`
2+
--------------------------------------------------------------------------
3+
4+
`.Axes.hist2d` now uses `~.Axes.pcolormesh` instead of `~.Axes.pcolorfast`,
5+
which will improve the handling of log-axes. Note that the
6+
returned *image* now is of type `~.matplotlib.collections.QuadMesh`
7+
instead of `~.matplotlib.image.AxesImage`.

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6505,7 +6505,7 @@ def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
65056505
The bin edges along the x axis.
65066506
yedges : 1D array
65076507
The bin edges along the y axis.
6508-
image : AxesImage
6508+
image : `~.matplotlib.collections.QuadMesh`
65096509
65106510
Other Parameters
65116511
----------------
@@ -6545,7 +6545,7 @@ def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
65456545
if cmax is not None:
65466546
h[h > cmax] = None
65476547

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

Binary file not shown.
Loading

lib/matplotlib/tests/baseline_images/test_axes/hist2d.svg

Lines changed: 54 additions & 367 deletions
Loading
Binary file not shown.

lib/matplotlib/tests/baseline_images/test_axes/hist2d_transpose.svg

Lines changed: 54 additions & 405 deletions
Loading

lib/matplotlib/tests/test_axes.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,24 +1646,26 @@ def test_contour_colorbar():
16461646
cbar.add_lines(cs2, erase=False)
16471647

16481648

1649-
@image_comparison(baseline_images=['hist2d', 'hist2d'])
1649+
@image_comparison(baseline_images=['hist2d', 'hist2d'],
1650+
remove_text=True, style='mpl20')
16501651
def test_hist2d():
16511652
np.random.seed(0)
16521653
# make it not symmetric in case we switch x and y axis
16531654
x = np.random.randn(100)*2+5
16541655
y = np.random.randn(100)-2
16551656
fig = plt.figure()
16561657
ax = fig.add_subplot(111)
1657-
ax.hist2d(x, y, bins=10)
1658+
ax.hist2d(x, y, bins=10, rasterized=True)
16581659

16591660
# Reuse testcase from above for a labeled data test
16601661
data = {"x": x, "y": y}
16611662
fig = plt.figure()
16621663
ax = fig.add_subplot(111)
1663-
ax.hist2d("x", "y", bins=10, data=data)
1664+
ax.hist2d("x", "y", bins=10, data=data, rasterized=True)
16641665

16651666

1666-
@image_comparison(baseline_images=['hist2d_transpose'])
1667+
@image_comparison(baseline_images=['hist2d_transpose'],
1668+
remove_text=True, style='mpl20')
16671669
def test_hist2d_transpose():
16681670
np.random.seed(0)
16691671
# make sure the output from np.histogram is transposed before
@@ -1672,7 +1674,7 @@ def test_hist2d_transpose():
16721674
y = np.random.randn(100)-2
16731675
fig = plt.figure()
16741676
ax = fig.add_subplot(111)
1675-
ax.hist2d(x, y, bins=10)
1677+
ax.hist2d(x, y, bins=10, rasterized=True)
16761678

16771679

16781680
@image_comparison(baseline_images=['scatter', 'scatter'])

lib/matplotlib/tests/test_image.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -586,12 +586,6 @@ def test_pcolorimage_setdata():
586586
assert im._A[0, 0] == im._Ax[0] == im._Ay[0] == 0, 'value changed'
587587

588588

589-
def test_pcolorimage_extent():
590-
im = plt.hist2d([1, 2, 3], [3, 5, 6],
591-
bins=[[0, 3, 7], [1, 2, 3]])[-1]
592-
assert im.get_extent() == (0, 7, 1, 3)
593-
594-
595589
def test_minimized_rasterized():
596590
# This ensures that the rasterized content in the colorbars is
597591
# only as thick as the colorbar, and doesn't extend to other parts

0 commit comments

Comments
 (0)