Skip to content

Commit 9ba3872

Browse files
committed
BUG : fix cla behavior with twinx
Closes #3633 Added more special-case logic for twined axes. This needs a test
1 parent 68b34b0 commit 9ba3872

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,16 @@ def _gen_axes_spines(self, locations=None, offset=0.0, units='inches'):
816816
def cla(self):
817817
"""Clear the current axes."""
818818
# Note: this is called by Axes.__init__()
819+
820+
# stash the current visibility state
821+
if hasattr(self, 'patch'):
822+
patch_visible = self.patch.get_visible()
823+
else:
824+
patch_visible = True
825+
826+
yaxis_visible = self.xaxis.get_visible()
827+
xaxis_visible = self.yaxis.get_visible()
828+
819829
self.xaxis.cla()
820830
self.yaxis.cla()
821831
for name, spine in six.iteritems(self.spines):
@@ -941,6 +951,13 @@ def cla(self):
941951

942952
self._shared_x_axes.clean()
943953
self._shared_y_axes.clean()
954+
if self._sharex:
955+
self.xaxis.set_visible(xaxis_visible)
956+
self.patch.set_visible(patch_visible)
957+
958+
if self._sharey:
959+
self.yaxis.set_visible(yaxis_visible)
960+
self.patch.set_visible(patch_visible)
944961

945962
def clear(self):
946963
"""clear the axes"""

0 commit comments

Comments
 (0)