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

Skip to content

Add ability to unshare a pair of shared [xy] axes #1312

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 1 commit 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
58 changes: 46 additions & 12 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,6 @@ class _AxesBase(martist.Artist):
"""
name = "rectilinear"

_shared_x_axes = cbook.Grouper()
_shared_y_axes = cbook.Grouper()

def __str__(self):
return "Axes(%g,%g;%gx%g)" % tuple(self._position.bounds)

Expand Down Expand Up @@ -391,17 +388,23 @@ def __init__(self, fig, rect,
self.set_aspect('auto')
self._adjustable = 'box'
self.set_anchor('C')

self._shared_x_axes = []
self._shared_y_axes = []

self._sharex = sharex
self._sharey = sharey
if sharex is not None:
self._shared_x_axes.join(self, sharex)
self._shared_x_axes.append(sharex)
sharex._shared_x_axes.append(self)
if sharex._adjustable == 'box':
sharex._adjustable = 'datalim'
#warnings.warn(
# 'shared axes: "adjustable" is being changed to "datalim"')
self._adjustable = 'datalim'
if sharey is not None:
self._shared_y_axes.join(self, sharey)
self._shared_y_axes.append(sharey)
sharey._shared_y_axes.append(self)
if sharey._adjustable == 'box':
sharey._adjustable = 'datalim'
#warnings.warn(
Expand Down Expand Up @@ -934,9 +937,6 @@ def cla(self):
self.xaxis.set_clip_path(self.patch)
self.yaxis.set_clip_path(self.patch)

self._shared_x_axes.clean()
self._shared_y_axes.clean()

def clear(self):
"""clear the axes"""
self.cla()
Expand Down Expand Up @@ -1893,7 +1893,8 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
_tight = self._tight = bool(tight)

if scalex and self._autoscaleXon:
xshared = self._shared_x_axes.get_siblings(self)
xshared = self._shared_x_axes[:]
xshared.append(self)
dl = [ax.dataLim for ax in xshared]
bb = mtransforms.BboxBase.union(dl)
x0, x1 = bb.intervalx
Expand All @@ -1914,7 +1915,8 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
self.set_xbound(x0, x1)

if scaley and self._autoscaleYon:
yshared = self._shared_y_axes.get_siblings(self)
yshared = self._shared_y_axes[:]
yshared.append(self)
dl = [ax.dataLim for ax in yshared]
bb = mtransforms.BboxBase.union(dl)
y0, y1 = bb.intervaly
Expand Down Expand Up @@ -2515,7 +2517,7 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
if emit:
self.callbacks.process('xlim_changed', self)
# Call all of the other x-axes that are shared with this one
for other in self._shared_x_axes.get_siblings(self):
for other in self._shared_x_axes:
if other is not self:
other.set_xlim(self.viewLim.intervalx,
emit=False, auto=auto)
Expand Down Expand Up @@ -2741,7 +2743,7 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw):
if emit:
self.callbacks.process('ylim_changed', self)
# Call all of the other y-axes that are shared with this one
for other in self._shared_y_axes.get_siblings(self):
for other in self._shared_y_axes:
if other is not self:
other.set_ylim(self.viewLim.intervaly,
emit=False, auto=auto)
Expand Down Expand Up @@ -3250,4 +3252,36 @@ def get_shared_y_axes(self):
'Return a copy of the shared axes Grouper object for y axes'
return self._shared_y_axes

def unshare_x_axes(self, ax):
"""Unshare the shared x axes between *ax* and *self*"""
ax_shared_x = ax.get_shared_x_axes()

self._shared_x_axes.remove(ax)
ax_shared_x.remove(self)

self._sharex = None
ax._sharex = None

# Only set adjustable back to 'box' if there are no other shared axes
if len([axkey for axkey in self._shared_x_axes]) == 0:
self.set_adjustable('box')

if len([axkey for axkey in ax_shared_x]) == 0:
ax.set_adjustable('box')

def unshare_y_axes(self, ax):
"""Unshare the shared y axes between *ax* and *self*"""
ax_shared_y = ax.get_shared_y_axes()

self._shared_y_axes.remove(ax)
ax_shared_y.remove(self)

self._sharey = None
ax._sharey = None

# Only set adjustable back to 'box' if there are no other shared axes
if len([axkey for axkey in self._shared_y_axes]) == 0:
self.set_adjustable('box')

if len([axkey for axkey in ax_shared_y]) == 0:
ax.set_adjustable('box')