Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 799946c

Browse files
committed
Don't clear a new Axis when registering with a Spine.
If the Axis was just created, calling Axis.cla is redundant because it just happened.
1 parent ad222a2 commit 799946c

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -607,11 +607,11 @@ def get_window_extent(self, *args, **kwargs):
607607
def _init_axis(self):
608608
"move this out of __init__ because non-separable axes don't use it"
609609
self.xaxis = maxis.XAxis(self)
610-
self.spines['bottom'].register_axis(self.xaxis)
611-
self.spines['top'].register_axis(self.xaxis)
610+
self.spines['bottom'].register_axis(self.xaxis, _init=True)
611+
self.spines['top'].register_axis(self.xaxis, _init=True)
612612
self.yaxis = maxis.YAxis(self)
613-
self.spines['left'].register_axis(self.yaxis)
614-
self.spines['right'].register_axis(self.yaxis)
613+
self.spines['left'].register_axis(self.yaxis, _init=True)
614+
self.spines['right'].register_axis(self.yaxis, _init=True)
615615
self._update_transScale()
616616

617617
def set_figure(self, fig):

lib/matplotlib/spines.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,17 @@ def _ensure_position_is_set(self):
151151
self._position = ('outward', 0.0) # in points
152152
self.set_position(self._position)
153153

154-
def register_axis(self, axis):
154+
def register_axis(self, axis, _init=False):
155155
"""register an axis
156156
157157
An axis should be registered with its corresponding spine from
158158
the Axes instance. This allows the spine to clear any axis
159159
properties when needed.
160160
"""
161161
self.axis = axis
162-
if self.axis is not None:
162+
if not _init and self.axis is not None:
163+
# Clear the axis when added, but *not* if the caller says it was
164+
# just created.
163165
self.axis.cla()
164166
self.stale = True
165167

0 commit comments

Comments
 (0)