Skip to content

moved cla shared axes code to a dedicated function #8710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 45 additions & 40 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,28 +973,9 @@ def cla(self):
self.ignore_existing_data_limits = True
self.callbacks = cbook.CallbackRegistry()

# clear the shared axes
if self._sharex is not None:
# major and minor are class instances with
# locator and formatter attributes
self.xaxis.major = self._sharex.xaxis.major
self.xaxis.minor = self._sharex.xaxis.minor
x0, x1 = self._sharex.get_xlim()
self.set_xlim(x0, x1, emit=False, auto=None)

# Save the current formatter/locator so we don't lose it
majf = self._sharex.xaxis.get_major_formatter()
minf = self._sharex.xaxis.get_minor_formatter()
majl = self._sharex.xaxis.get_major_locator()
minl = self._sharex.xaxis.get_minor_locator()

# This overwrites the current formatter/locator
self.xaxis._set_scale(self._sharex.xaxis.get_scale())

# Reset the formatter/locator
self.xaxis.set_major_formatter(majf)
self.xaxis.set_minor_formatter(minf)
self.xaxis.set_major_locator(majl)
self.xaxis.set_minor_locator(minl)
self._cla_shared("x")
else:
self.xaxis._set_scale('linear')
try:
Expand All @@ -1003,25 +984,7 @@ def cla(self):
pass

if self._sharey is not None:
self.yaxis.major = self._sharey.yaxis.major
self.yaxis.minor = self._sharey.yaxis.minor
y0, y1 = self._sharey.get_ylim()
self.set_ylim(y0, y1, emit=False, auto=None)

# Save the current formatter/locator so we don't lose it
majf = self._sharey.yaxis.get_major_formatter()
minf = self._sharey.yaxis.get_minor_formatter()
majl = self._sharey.yaxis.get_major_locator()
minl = self._sharey.yaxis.get_minor_locator()

# This overwrites the current formatter/locator
self.yaxis._set_scale(self._sharey.yaxis.get_scale())

# Reset the formatter/locator
self.yaxis.set_major_formatter(majf)
self.yaxis.set_minor_formatter(minf)
self.yaxis.set_major_locator(majl)
self.yaxis.set_minor_locator(minl)
self._cla_shared("y")
else:
self.yaxis._set_scale('linear')
try:
Expand Down Expand Up @@ -1121,6 +1084,48 @@ def cla(self):

self.stale = True

def _cla_shared(self, axistype):
''' clear the shared axes, for the given axis type.
Note : if cla is overrided, this method must
not be used.
'''
# major and minor are class instances with
# locator and formatter attributes
if not isinstance(axistype, str):
raise ValueError("Axis type is not a string (x or y for example)")
# ex : "self.xaxis"
axis = getattr(self, axistype + "axis")
# ex : self._sharex
share = getattr(self, "_share" + axistype)
# ex : self._sharex.xaxis
shareaxis = getattr(share, axistype+"axis")
# ex : self._sharex.get_xlim
limget = getattr(share, "get_"+axistype+"lim")
# ex : self.set_xlim
limset = getattr(self, "set_"+axistype+"lim")

# major and minor are class instances with
# locator and formatter attributes
axis.major = shareaxis.major
axis.minor = shareaxis.minor
x0, x1 = limget()
limset(x0, x1, emit=False, auto=None)

# Save the current formatter/locator so we don't lose it
majf = shareaxis.get_major_formatter()
minf = shareaxis.get_minor_formatter()
majl = shareaxis.get_major_locator()
minl = shareaxis.get_minor_locator()

# This overwrites the current formatter/locator
axis._set_scale(shareaxis.get_scale())

# Reset the formatter/locator
axis.set_major_formatter(majf)
axis.set_minor_formatter(minf)
axis.set_major_locator(majl)
axis.set_minor_locator(minl)

@cbook.deprecated("2.1", alternative="Axes.patch")
def axesPatch(self):
return self.patch
Expand Down