Skip to content

Commit 3354584

Browse files
committed
Style-clean parasite axes.
1 parent cd500c7 commit 3354584

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

.flake8

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ per-file-ignores =
7070
mpl_toolkits/axes_grid1/colorbar.py: E225, E231, E261, E262, E302, E303, E501, E701
7171
mpl_toolkits/axes_grid1/inset_locator.py: E501
7272
mpl_toolkits/axes_grid1/mpl_axes.py: E303, E501
73-
mpl_toolkits/axes_grid1/parasite_axes.py: E225, E231, E302, E303, E501
7473
mpl_toolkits/axisartist/angle_helper.py: E201, E203, E221, E222, E225, E231, E251, E261, E262, E302, E303, E501
7574
mpl_toolkits/axisartist/axis_artist.py: E201, E202, E221, E225, E228, E231, E251, E261, E262, E302, E303, E402, E501, E701, E711
7675
mpl_toolkits/axisartist/axisline_style.py: E231, E261, E262, E302, E303

lib/mpl_toolkits/axes_grid1/parasite_axes.py

+17-28
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def _set_lim_and_transforms(self):
7575

7676
def set_viewlim_mode(self, mode):
7777
if mode not in [None, "equal", "transform"]:
78-
raise ValueError("Unknown mode : %s" % (mode,))
78+
raise ValueError("Unknown mode: %s" % (mode,))
7979
else:
8080
self._viewlim_mode = mode
8181

@@ -90,17 +90,18 @@ def update_viewlim(self):
9090
elif mode == "equal":
9191
self.axes.viewLim.set(viewlim)
9292
elif mode == "transform":
93-
self.axes.viewLim.set(viewlim.transformed(self.transAux.inverted()))
93+
self.axes.viewLim.set(
94+
viewlim.transformed(self.transAux.inverted()))
9495
else:
95-
raise ValueError("Unknown mode : %s" % (self._viewlim_mode,))
96+
raise ValueError("Unknown mode: %s" % (self._viewlim_mode,))
9697

9798
def _pcolor(self, super_pcolor, *XYC, **kwargs):
9899
if len(XYC) == 1:
99100
C = XYC[0]
100101
ny, nx = C.shape
101102

102-
gx = np.arange(-0.5, nx, 1.)
103-
gy = np.arange(-0.5, ny, 1.)
103+
gx = np.arange(-0.5, nx)
104+
gy = np.arange(-0.5, ny)
104105

105106
X, Y = np.meshgrid(gx, gy)
106107
else:
@@ -110,10 +111,10 @@ def _pcolor(self, super_pcolor, *XYC, **kwargs):
110111
mesh = super_pcolor(self, X, Y, C, **kwargs)
111112
else:
112113
orig_shape = X.shape
113-
xy = np.vstack([X.flat, Y.flat])
114-
xyt=xy.transpose()
114+
xyt = np.column_stack([X.flat, Y.flat])
115115
wxy = self.transAux.transform(xyt)
116-
gx, gy = wxy[:,0].reshape(orig_shape), wxy[:,1].reshape(orig_shape)
116+
gx = wxy[:, 0].reshape(orig_shape)
117+
gy = wxy[:, 1].reshape(orig_shape)
117118
mesh = super_pcolor(self, gx, gy, C, **kwargs)
118119
mesh.set_transform(self._parent_axes.transData)
119120

@@ -131,10 +132,10 @@ def _contour(self, super_contour, *XYCL, **kwargs):
131132
C = XYCL[0]
132133
ny, nx = C.shape
133134

134-
gx = np.arange(0., nx, 1.)
135-
gy = np.arange(0., ny, 1.)
135+
gx = np.arange(0., nx)
136+
gy = np.arange(0., ny)
136137

137-
X,Y = np.meshgrid(gx, gy)
138+
X, Y = np.meshgrid(gx, gy)
138139
CL = XYCL
139140
else:
140141
X, Y = XYCL[:2]
@@ -144,10 +145,10 @@ def _contour(self, super_contour, *XYCL, **kwargs):
144145
cont = super_contour(self, X, Y, *CL, **kwargs)
145146
else:
146147
orig_shape = X.shape
147-
xy = np.vstack([X.flat, Y.flat])
148-
xyt=xy.transpose()
148+
xyt = np.column_stack([X.flat, Y.flat])
149149
wxy = self.transAux.transform(xyt)
150-
gx, gy = wxy[:,0].reshape(orig_shape), wxy[:,1].reshape(orig_shape)
150+
gx = wxy[:, 0].reshape(orig_shape)
151+
gy = wxy[:, 1].reshape(orig_shape)
151152
cont = super_contour(self, gx, gy, *CL, **kwargs)
152153
for c in cont.collections:
153154
c.set_transform(self._parent_axes.transData)
@@ -183,19 +184,6 @@ def parasite_axes_auxtrans_class_factory(axes_class=None):
183184
axes_class=ParasiteAxes)
184185

185186

186-
def _get_handles(ax):
187-
handles = ax.lines[:]
188-
handles.extend(ax.patches)
189-
handles.extend([c for c in ax.collections
190-
if isinstance(c, mcoll.LineCollection)])
191-
handles.extend([c for c in ax.collections
192-
if isinstance(c, mcoll.RegularPolyCollection)])
193-
handles.extend([c for c in ax.collections
194-
if isinstance(c, mcoll.CircleCollection)])
195-
196-
return handles
197-
198-
199187
class HostAxesBase:
200188
def __init__(self, *args, **kwargs):
201189
self.parasites = []
@@ -347,7 +335,7 @@ def get_tightbbox(self, renderer, call_axes_locator=True):
347335
bbs = [ax.get_tightbbox(renderer, call_axes_locator)
348336
for ax in self.parasites]
349337
bbs.append(super().get_tightbbox(renderer, call_axes_locator))
350-
return Bbox.union([b for b in bbs if b.width!=0 or b.height!=0])
338+
return Bbox.union([b for b in bbs if b.width != 0 or b.height != 0])
351339

352340

353341
@functools.lru_cache(None)
@@ -395,6 +383,7 @@ def host_axes(*args, axes_class=None, figure=None, **kwargs):
395383
plt.draw_if_interactive()
396384
return ax
397385

386+
398387
def host_subplot(*args, axes_class=None, figure=None, **kwargs):
399388
"""
400389
Create a subplot that can act as a host to parasitic axes.

0 commit comments

Comments
 (0)