Skip to content

Commit 8107d05

Browse files
committed
Do not clear Axis when registering spine
1 parent ebc7ade commit 8107d05

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -814,10 +814,10 @@ def get_window_extent(self, renderer=None):
814814

815815
def _init_axis(self):
816816
# This is moved out of __init__ because non-separable axes don't use it
817-
self.xaxis = maxis.XAxis(self)
817+
self.xaxis = maxis.XAxis(self, clear=False)
818818
self.spines.bottom.register_axis(self.xaxis)
819819
self.spines.top.register_axis(self.xaxis)
820-
self.yaxis = maxis.YAxis(self)
820+
self.yaxis = maxis.YAxis(self, clear=False)
821821
self.spines.left.register_axis(self.yaxis)
822822
self.spines.right.register_axis(self.yaxis)
823823

@@ -1272,8 +1272,7 @@ def __clear(self):
12721272
xaxis_visible = self.xaxis.get_visible()
12731273
yaxis_visible = self.yaxis.get_visible()
12741274

1275-
for axis in self._axis_map.values():
1276-
axis.clear() # Also resets the scale to linear.
1275+
# Clearing the spines also clears the axis, which resets the scale to linear
12771276
for spine in self.spines.values():
12781277
spine.clear()
12791278

lib/matplotlib/axis.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ def __str__(self):
632632
return "{}({},{})".format(
633633
type(self).__name__, *self.axes.transAxes.transform((0, 0)))
634634

635-
def __init__(self, axes, *, pickradius=15):
635+
def __init__(self, axes, *, pickradius=15, clear=True):
636636
"""
637637
Parameters
638638
----------
@@ -641,6 +641,8 @@ def __init__(self, axes, *, pickradius=15):
641641
pickradius : float
642642
The acceptance radius for containment tests. See also
643643
`.Axis.contains`.
644+
clear : bool, default: True
645+
Whether to clear the Axis on creation.
644646
"""
645647
super().__init__()
646648
self._remove_overlapping_locs = True
@@ -674,7 +676,8 @@ def __init__(self, axes, *, pickradius=15):
674676
self._major_tick_kw = dict()
675677
self._minor_tick_kw = dict()
676678

677-
self.clear()
679+
if clear:
680+
self.clear()
678681
self._autoscale_on = True
679682

680683
@property

lib/matplotlib/axis.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ class Axis(martist.Artist):
105105
offsetText: Text
106106
labelpad: float
107107
pickradius: float
108-
def __init__(self, axes, *, pickradius: float = ...) -> None: ...
108+
def __init__(self, axes, *, pickradius: float = ...,
109+
clear: bool = ...) -> None: ...
109110
@property
110111
def isDefault_majloc(self) -> bool: ...
111112
@isDefault_majloc.setter

lib/matplotlib/spines.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ def register_axis(self, axis):
214214
properties when needed.
215215
"""
216216
self.axis = axis
217-
if self.axis is not None:
218-
self.axis.clear()
219217
self.stale = True
220218

221219
def clear(self):

0 commit comments

Comments
 (0)