Skip to content

Commit 138f51f

Browse files
committed
Inline _init_axis_artists & _init_gridlines into clear.
clear() is the only caller of these inhernal axisartist helpers, so just inline them there. Note that these helpers are tightly coupled to clear() anyways (see the note about setting gridlines clip_path). Also, this makes it clearer that _init_axis_artist is never called with `axes != self` and that _init_gridlines is never called with `grid_helper != self.get_grid_helper()`. Also get rid of the `new_gridlines` helpers, which likewise become inlined.
1 parent 3301248 commit 138f51f

File tree

3 files changed

+46
-55
lines changed

3 files changed

+46
-55
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``axislines.GridHelperBase.new_gridlines`` and ``axislines.Axes.new_gridlines``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... are deprecated.

lib/mpl_toolkits/axes_grid1/mpl_axes.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,20 @@ def __getitem__(self, k):
4040
def __call__(self, *v, **kwargs):
4141
return maxes.Axes.axis(self.axes, *v, **kwargs)
4242

43-
def _init_axis_artists(self):
44-
self._axislines = self.AxisDict(self)
45-
self._axislines.update(
46-
bottom=SimpleAxisArtist(self.xaxis, 1, self.spines["bottom"]),
47-
top=SimpleAxisArtist(self.xaxis, 2, self.spines["top"]),
48-
left=SimpleAxisArtist(self.yaxis, 1, self.spines["left"]),
49-
right=SimpleAxisArtist(self.yaxis, 2, self.spines["right"]))
50-
5143
@property
5244
def axis(self):
5345
return self._axislines
5446

5547
def clear(self):
5648
# docstring inherited
5749
super().clear()
58-
self._init_axis_artists()
50+
# Init axis artists.
51+
self._axislines = self.AxisDict(self)
52+
self._axislines.update(
53+
bottom=SimpleAxisArtist(self.xaxis, 1, self.spines["bottom"]),
54+
top=SimpleAxisArtist(self.xaxis, 2, self.spines["top"]),
55+
left=SimpleAxisArtist(self.yaxis, 1, self.spines["left"]),
56+
right=SimpleAxisArtist(self.yaxis, 2, self.spines["right"]))
5957

6058

6159
class SimpleAxisArtist(Artist):

lib/mpl_toolkits/axisartist/axislines.py

Lines changed: 36 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ def get_gridlines(self, which, axis):
332332
"""
333333
return []
334334

335+
@_api.deprecated("3.6")
335336
def new_gridlines(self, ax):
336337
"""
337338
Create and return a new GridlineCollection instance.
@@ -462,25 +463,11 @@ def toggle_axisline(self, b=None):
462463
self.xaxis.set_visible(True)
463464
self.yaxis.set_visible(True)
464465

465-
def _init_axis_artists(self, axes=None):
466-
if axes is None:
467-
axes = self
468-
469-
self._axislines = mpl_axes.Axes.AxisDict(self)
470-
new_fixed_axis = self.get_grid_helper().new_fixed_axis
471-
for loc in ["bottom", "top", "left", "right"]:
472-
self._axislines[loc] = new_fixed_axis(loc=loc, axes=axes,
473-
axis_direction=loc)
474-
475-
for axisline in [self._axislines["top"], self._axislines["right"]]:
476-
axisline.label.set_visible(False)
477-
axisline.major_ticklabels.set_visible(False)
478-
axisline.minor_ticklabels.set_visible(False)
479-
480466
@property
481467
def axis(self):
482468
return self._axislines
483469

470+
@_api.deprecated("3.6")
484471
def new_gridlines(self, grid_helper=None):
485472
"""
486473
Create and return a new GridlineCollection instance.
@@ -495,21 +482,33 @@ def new_gridlines(self, grid_helper=None):
495482
gridlines = grid_helper.new_gridlines(self)
496483
return gridlines
497484

498-
def _init_gridlines(self, grid_helper=None):
499-
# It is done inside the cla.
500-
self.gridlines = self.new_gridlines(grid_helper)
501-
502485
def clear(self):
503486
# docstring inherited
504-
# gridlines need to be created before clear() since clear calls grid()
505-
self._init_gridlines()
487+
488+
# Init gridlines before clear() as clear() calls grid().
489+
self.gridlines = gridlines = GridlinesCollection(
490+
None, transform=self.transData,
491+
colors=rcParams['grid.color'],
492+
linestyles=rcParams['grid.linestyle'],
493+
linewidths=rcParams['grid.linewidth'])
494+
self._set_artist_props(gridlines)
495+
gridlines.set_grid_helper(self.get_grid_helper())
496+
506497
super().clear()
507498

508-
# the clip_path should be set after Axes.clear() since that's
509-
# when a patch is created.
510-
self.gridlines.set_clip_path(self.axes.patch)
499+
# clip_path is set after Axes.clear(): that's when a patch is created.
500+
gridlines.set_clip_path(self.axes.patch)
511501

512-
self._init_axis_artists()
502+
# Init axis artists.
503+
self._axislines = mpl_axes.Axes.AxisDict(self)
504+
new_fixed_axis = self.get_grid_helper().new_fixed_axis
505+
self._axislines.update({
506+
loc: new_fixed_axis(loc=loc, axes=self, axis_direction=loc)
507+
for loc in ["bottom", "top", "left", "right"]})
508+
for axisline in [self._axislines["top"], self._axislines["right"]]:
509+
axisline.label.set_visible(False)
510+
axisline.major_ticklabels.set_visible(False)
511+
axisline.minor_ticklabels.set_visible(False)
513512

514513
def get_grid_helper(self):
515514
return self._grid_helper
@@ -564,27 +563,18 @@ def new_floating_axis(self, nth_coord, value, axis_direction="bottom"):
564563

565564
class AxesZero(Axes):
566565

567-
def _init_axis_artists(self):
568-
super()._init_axis_artists()
569-
570-
new_floating_axis = self._grid_helper.new_floating_axis
571-
xaxis_zero = new_floating_axis(nth_coord=0,
572-
value=0.,
573-
axis_direction="bottom",
574-
axes=self)
575-
576-
xaxis_zero.line.set_clip_path(self.patch)
577-
xaxis_zero.set_visible(False)
578-
self._axislines["xzero"] = xaxis_zero
579-
580-
yaxis_zero = new_floating_axis(nth_coord=1,
581-
value=0.,
582-
axis_direction="left",
583-
axes=self)
584-
585-
yaxis_zero.line.set_clip_path(self.patch)
586-
yaxis_zero.set_visible(False)
587-
self._axislines["yzero"] = yaxis_zero
566+
def clear(self):
567+
super().clear()
568+
new_floating_axis = self.get_grid_helper().new_floating_axis
569+
self._axislines.update(
570+
xzero=new_floating_axis(
571+
nth_coord=0, value=0., axis_direction="bottom", axes=self),
572+
yzero=new_floating_axis(
573+
nth_coord=1, value=0., axis_direction="left", axes=self),
574+
)
575+
for k in ["xzero", "yzero"]:
576+
self._axislines[k].line.set_clip_path(self.patch)
577+
self._axislines[k].set_visible(False)
588578

589579

590580
SubplotZero = maxes.subplot_class_factory(AxesZero)

0 commit comments

Comments
 (0)