diff --git a/doc/api/next_api_changes/behavior/18560-AL.rst b/doc/api/next_api_changes/behavior/18560-AL.rst new file mode 100644 index 000000000000..abe54fa2e37e --- /dev/null +++ b/doc/api/next_api_changes/behavior/18560-AL.rst @@ -0,0 +1,4 @@ +Parasite Axes pcolor and pcolormesh now defaults to placing grid edges at integers, not half-integers +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +This is consistent with `~.Axes.pcolor` and `~.Axes.pcolormesh`. diff --git a/examples/axisartist/demo_curvelinear_grid.py b/examples/axisartist/demo_curvelinear_grid.py index 9d1d4f7b3f76..b2fa2bcce5e2 100644 --- a/examples/axisartist/demo_curvelinear_grid.py +++ b/examples/axisartist/demo_curvelinear_grid.py @@ -109,6 +109,11 @@ def curvelinear_test2(fig): ax1.parasites.append(ax2) ax2.plot(np.linspace(0, 30, 51), np.linspace(10, 10, 51), linewidth=2) + ax2.pcolor(np.linspace(0, 90, 4), np.linspace(0, 10, 4), + np.arange(9).reshape((3, 3))) + ax2.contour(np.linspace(0, 90, 4), np.linspace(0, 10, 4), + np.arange(16).reshape((4, 4)), colors="k") + if __name__ == "__main__": fig = plt.figure(figsize=(7, 4)) diff --git a/lib/mpl_toolkits/axes_grid1/parasite_axes.py b/lib/mpl_toolkits/axes_grid1/parasite_axes.py index d69b8016070b..69e3b50424c0 100644 --- a/lib/mpl_toolkits/axes_grid1/parasite_axes.py +++ b/lib/mpl_toolkits/axes_grid1/parasite_axes.py @@ -7,8 +7,6 @@ from matplotlib.transforms import Bbox from .mpl_axes import Axes -import numpy as np - class ParasiteAxesBase: @@ -108,72 +106,6 @@ def update_viewlim(self): else: _api.check_in_list([None, "equal", "transform"], mode=mode) - def _pcolor(self, super_pcolor, *XYC, **kwargs): - if len(XYC) == 1: - C = XYC[0] - ny, nx = C.shape - - gx = np.arange(-0.5, nx) - gy = np.arange(-0.5, ny) - - X, Y = np.meshgrid(gx, gy) - else: - X, Y, C = XYC - - if "transform" in kwargs: - mesh = super_pcolor(X, Y, C, **kwargs) - else: - orig_shape = X.shape - xyt = np.column_stack([X.flat, Y.flat]) - wxy = self.transAux.transform(xyt) - gx = wxy[:, 0].reshape(orig_shape) - gy = wxy[:, 1].reshape(orig_shape) - mesh = super_pcolor(gx, gy, C, **kwargs) - mesh.set_transform(self._parent_axes.transData) - - return mesh - - def pcolormesh(self, *XYC, **kwargs): - return self._pcolor(super().pcolormesh, *XYC, **kwargs) - - def pcolor(self, *XYC, **kwargs): - return self._pcolor(super().pcolor, *XYC, **kwargs) - - def _contour(self, super_contour, *XYCL, **kwargs): - - if len(XYCL) <= 2: - C = XYCL[0] - ny, nx = C.shape - - gx = np.arange(0., nx) - gy = np.arange(0., ny) - - X, Y = np.meshgrid(gx, gy) - CL = XYCL - else: - X, Y = XYCL[:2] - CL = XYCL[2:] - - if "transform" in kwargs: - cont = super_contour(X, Y, *CL, **kwargs) - else: - orig_shape = X.shape - xyt = np.column_stack([X.flat, Y.flat]) - wxy = self.transAux.transform(xyt) - gx = wxy[:, 0].reshape(orig_shape) - gy = wxy[:, 1].reshape(orig_shape) - cont = super_contour(gx, gy, *CL, **kwargs) - for c in cont.collections: - c.set_transform(self._parent_axes.transData) - - return cont - - def contour(self, *XYCL, **kwargs): - return self._contour(super().contour, *XYCL, **kwargs) - - def contourf(self, *XYCL, **kwargs): - return self._contour(super().contourf, *XYCL, **kwargs) - def apply_aspect(self, position=None): self.update_viewlim() super().apply_aspect()