diff --git a/doc/api/next_api_changes/2017-12-12-JMK.rst b/doc/api/next_api_changes/2017-12-12-JMK.rst new file mode 100644 index 000000000000..ff7af6595872 --- /dev/null +++ b/doc/api/next_api_changes/2017-12-12-JMK.rst @@ -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`. diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 0292ccb64218..bb0402a88f8a 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -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 ---------------- @@ -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]) diff --git a/lib/matplotlib/tests/baseline_images/test_axes/hist2d.pdf b/lib/matplotlib/tests/baseline_images/test_axes/hist2d.pdf index 2960fe060b19..8343cc2efd97 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/hist2d.pdf and b/lib/matplotlib/tests/baseline_images/test_axes/hist2d.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/hist2d.png b/lib/matplotlib/tests/baseline_images/test_axes/hist2d.png index 19cf02780009..07fd623e9137 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/hist2d.png and b/lib/matplotlib/tests/baseline_images/test_axes/hist2d.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/hist2d.svg b/lib/matplotlib/tests/baseline_images/test_axes/hist2d.svg index de5552ab36bb..025441b800db 100644 --- a/lib/matplotlib/tests/baseline_images/test_axes/hist2d.svg +++ b/lib/matplotlib/tests/baseline_images/test_axes/hist2d.svg @@ -1,8 +1,8 @@ - - + + - - - - - - - - - - - - - - - + - - - - - - - - +L 0 3.5 +" id="m0b727597d4" style="stroke:#000000;stroke-width:0.8;"/> - - - - - - - - - - + - - - - - - + - - - - - - - - - - + - - - - - - + - - - - - - - - - - + - - - - - - + - - - - - - - - - - + - - - - - - + - - - - - - - - - - + - - - - - - - - - + +L -3.5 0 +" id="m4baa07b7ca" style="stroke:#000000;stroke-width:0.8;"/> - - - - - - - - - - - + - - - - - - + - - - - - - - - - - - + - - - - - - + - - - - - - - - + - - - - - - + - - - - - - - - - - - + - - - - - - + - - - - - - - + + + + + + + + + + + + + diff --git a/lib/matplotlib/tests/baseline_images/test_axes/hist2d_transpose.pdf b/lib/matplotlib/tests/baseline_images/test_axes/hist2d_transpose.pdf index 919ae14014e6..d7a58f772a40 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/hist2d_transpose.pdf and b/lib/matplotlib/tests/baseline_images/test_axes/hist2d_transpose.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/hist2d_transpose.png b/lib/matplotlib/tests/baseline_images/test_axes/hist2d_transpose.png index 9ec9980c498f..1979567f6b24 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/hist2d_transpose.png and b/lib/matplotlib/tests/baseline_images/test_axes/hist2d_transpose.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/hist2d_transpose.svg b/lib/matplotlib/tests/baseline_images/test_axes/hist2d_transpose.svg index 240f7789944a..8111cb56486a 100644 --- a/lib/matplotlib/tests/baseline_images/test_axes/hist2d_transpose.svg +++ b/lib/matplotlib/tests/baseline_images/test_axes/hist2d_transpose.svg @@ -1,8 +1,8 @@ - - + + - - - - - - - - - - - - - - - + - - - - - - - - +L 0 3.5 +" id="m430282c97a" style="stroke:#000000;stroke-width:0.8;"/> - - - - - - - - - - - - - - + - - - - - - + - - - - - - - - - - - - + - - - - - - + - - - - - - - - - - - - - + - - - - - - + - - - - - - - - - - - - + - - - - - - + - - - - - - - - - + - - - - - - - - - + +L -3.5 0 +" id="md176de54a1" style="stroke:#000000;stroke-width:0.8;"/> - - - - - - - - - - - + - - - - - - + - - - - - - - - - - - + - - - - - - + - - - - - - - - + - - - - - - + - - - - - - - - - - - + - - - - - - + - - - - - - - + + + + + + + + + + + + + diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 6eae5a7227d5..7ef9445e6af0 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -1646,7 +1646,8 @@ 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 @@ -1654,16 +1655,17 @@ def test_hist2d(): 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) # 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 @@ -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']) diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index a1feed5e4dca..82c44ffad0ca 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -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(): - 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