8000 Remove incorrect override of pcolor/contour in parasite axes. · matplotlib/matplotlib@b763649 · GitHub
[go: up one dir, main page]

Skip to content

Commit b763649

Browse files
committed
Remove incorrect override of pcolor/contour in parasite axes.
The override of `pcolor`, `pcolormesh`, `contour`, and `contourf` in parasite axes was actually incorrect. Perhaps things were different when that code went in, but nowadays things work just fine without any need for overriding. See e.g. the new version of demo_curvelinear_grid before and after the changes. The default gridding of `pcolor`/`pcolormesh` changed to match the one of normal Axes; I don't think this is worth going through a deprecation period...
1 parent 5b835ee commit b763649

File tree

3 files changed

+9
-68
lines changed

3 files changed

+9
-68
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Parasite Axes pcolor and pcolormesh now defaults to placing grid edges at integers, not half-integers
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
This is consistent with `~.Axes.pcolor` and `~.Axes.pcolormesh`.

examples/axisartist/demo_curvelinear_grid.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ def curvelinear_test2(fig):
109109
ax1.parasites.append(ax2)
110110
ax2.plot(np.linspace(0, 30, 51), np.linspace(10, 10, 51), linewidth=2)
111111

112+
ax2.pcolor(np.linspace(0, 90, 4), np.linspace(0, 10, 4),
113+
np.arange(9).reshape((3, 3)))
114+
ax2.contour(np.linspace(0, 90, 4), np.linspace(0, 10, 4),
115+
np.arange(16).reshape((4, 4)), colors="k")
116+
112117

113118
if __name__ == "__main__":
114119
fig = plt.figure(figsize=(7, 4))

lib/mpl_toolkits/axes_grid1/parasite_axes.py

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
from matplotlib.transforms import Bbox
88
from .mpl_axes import Axes
99

10-
import numpy as np
11-
1210

1311
class ParasiteAxesBase:
1412

@@ -108,72 +106,6 @@ def update_viewlim(self):
108106
else:
109107
_api.check_in_list([None, "equal", "transform"], mode=mode)
110108

111-
def _pcolor(self, super_pcolor, *XYC, **kwargs):
112-
if len(XYC) == 1:
113-
C = XYC[0]
114-
ny, nx = C.shape
115-
116-
gx = np.arange(-0.5, nx)
117-
gy = np.arange(-0.5, ny)
118-
119-
X, Y = np.meshgrid(gx, gy)
120-
else:
121-
X, Y, C = XYC
122-
123-
if "transform" in kwargs:
124-
mesh = super_pcolor(X, Y, C, **kwargs)
125-
else:
126-
orig_shape = X.shape
127-
xyt = np.column_stack([X.flat, Y.flat])
128-
wxy = self.transAux.transform(xyt)
129-
gx = wxy[:, 0].reshape(orig_shape)
130-
gy = wxy[:, 1].reshape(orig_shape)
131-
mesh = super_pcolor(gx, gy, C, **kwargs)
132-
mesh.set_transform(self._parent_axes.transData)
133-
134-
return mesh
135-
136-
def pcolormesh(self, *XYC, **kwargs):
137-
return self._pcolor(super().pcolormesh, *XYC, **kwargs)
138-
139-
def pcolor(self, *XYC, **kwargs):
140-
return self._pcolor(super().pcolor, *XYC, **kwargs)
141-
142-
def _contour(self, super_contour, *XYCL, **kwargs):
143-
144-
if len(XYCL) <= 2:
145-
C = XYCL[0]
146-
ny, nx = C.shape
147-
148-
gx = np.arange(0., nx)
149-
gy = np.arange(0., ny)
150-
151-
X, Y = np.meshgrid(gx, gy)
152-
CL = XYCL
153-
else:
154-
X, Y = XYCL[:2]
155-
CL = XYCL[2:]
156-
157-
if "transform" in kwargs:
158-
cont = super_contour(X, Y, *CL, **kwargs)
159-
else:
160-
orig_shape = X.shape
161-
xyt = np.column_stack([X.flat, Y.flat])
162-
wxy = self.transAux.transform(xyt)
163-
gx = wxy[:, 0].reshape(orig_shape)
164-
gy = wxy[:, 1].reshape(orig_shape)
165-
cont = super_contour(gx, gy, *CL, **kwargs)
166-
for c in cont.collections:
167-
c.set_transform(self._parent_axes.transData)
168-
169-
return cont
170-
171-
def contour(self, *XYCL, **kwargs):
172-
return self._contour(super().contour, *XYCL, **kwargs)
173-
174-
def contourf(self, *XYCL, **kwargs):
175-
return self._contour(super().contourf, *XYCL, **kwargs)
176-
177109
def apply_aspect(self, position=None):
178110
self.update_viewlim()
179111
super().apply_aspect()

0 commit comments

Comments
 (0)
0