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

Skip to content

Commit ad222a2

Browse files
committed
Don't clear Spines and Axis twice in Axes.__init__.
Both these classes have called their own .cla() method in their .__init__() method, so don't call it again in Axes.cla() if doing Axes.__init__().
1 parent 1e53be3 commit ad222a2

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ def __init__(self, fig, rect,
537537
self._hold = True
538538

539539
self._connected = {} # a dict from events to (id, func)
540-
self.cla()
540+
self.cla(_init=True)
541541
# funcs used to format x and y - fall back on major formatters
542542
self.fmt_xdata = None
543543
self.fmt_ydata = None
@@ -952,7 +952,7 @@ def _gen_axes_spines(self, locations=None, offset=0.0, units='inches'):
952952
('bottom', mspines.Spine.linear_spine(self, 'bottom')),
953953
('top', mspines.Spine.linear_spine(self, 'top'))])
954954

955-
def cla(self):
955+
def cla(self, _init=False):
956956
"""Clear the current axes."""
957957
# Note: this is called by Axes.__init__()
958958

@@ -965,10 +965,13 @@ def cla(self):
965965
xaxis_visible = self.xaxis.get_visible()
966966
yaxis_visible = self.yaxis.get_visible()
967967

968-
self.xaxis.cla()
969-
self.yaxis.cla()
970-
for name, spine in six.iteritems(self.spines):
971-
spine.cla()
968+
# Don't clear during __init__ because they're already been cleared by
969+
# their own __init__.
970+
if not _init:
971+
self.xaxis.cla()
972+
self.yaxis.cla()
973+
for name, spine in six.iteritems(self.spines):
974+
spine.cla()
972975

973976
self.ignore_existing_data_limits = True
974977
self.callbacks = cbook.CallbackRegistry()

0 commit comments

Comments
 (0)