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

Skip to content

Commit 2525493

Browse files
committed
When initializing a shared axes, respect limits already set on master.
This is a tentative first step; more will be required. svn path=/trunk/matplotlib/; revision=6301
1 parent 2c3c907 commit 2525493

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

lib/matplotlib/axes.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,6 @@ def __init__(self, fig, rect,
501501
self.set_aspect('auto')
502502
self.set_adjustable('box')
503503
self.set_anchor('C')
504-
505504
self._sharex = sharex
506505
self._sharey = sharey
507506
if sharex is not None:
@@ -523,7 +522,6 @@ def __init__(self, fig, rect,
523522
self._hold = rcParams['axes.hold']
524523
self._connected = {} # a dict from events to (id, func)
525524
self.cla()
526-
527525
# funcs used to format x and y - fall back on major formatters
528526
self.fmt_xdata = None
529527
self.fmt_ydata = None
@@ -798,18 +796,35 @@ def _gen_axes_patch(self):
798796

799797
def cla(self):
800798
'Clear the current axes'
799+
# Note: this is called by Axes.__init__()
801800
self.xaxis.cla()
802801
self.yaxis.cla()
803802

804803
self.ignore_existing_data_limits = True
805804
self.callbacks = cbook.CallbackRegistry(('xlim_changed', 'ylim_changed'))
806805

807806
if self._sharex is not None:
807+
# major and minor are class instances with
808+
# locator and formatter attributes
808809
self.xaxis.major = self._sharex.xaxis.major
809810
self.xaxis.minor = self._sharex.xaxis.minor
811+
x0, x1 = self._sharex.get_xlim()
812+
self.set_xlim(x0, x1, emit=False)
813+
self.xaxis.set_scale(self._sharex.xaxis.get_scale())
814+
else:
815+
self.xaxis.set_scale('linear')
816+
810817
if self._sharey is not None:
811818
self.yaxis.major = self._sharey.yaxis.major
812819
self.yaxis.minor = self._sharey.yaxis.minor
820+
y0, y1 = self._sharex.get_ylim()
821+
self.set_ylim(y0, y1, emit=False)
822+
self.yaxis.set_scale(self._sharey.yaxis.get_scale())
823+
else:
824+
self.yaxis.set_scale('linear')
825+
826+
self._autoscaleon = True
827+
self._update_transScale() # needed?
813828

814829
self._get_lines = _process_plot_var_args(self)
815830
self._get_patches_for_fill = _process_plot_var_args(self, 'fill')
@@ -824,10 +839,6 @@ def cla(self):
824839
self.legend_ = None
825840
self.collections = [] # collection.Collection instances
826841

827-
self._autoscaleon = True
828-
self.set_xscale('linear')
829-
self.set_yscale('linear')
830-
831842
self.grid(self._gridOn)
832843
props = font_manager.FontProperties(size=rcParams['axes.titlesize'])
833844

@@ -1769,10 +1780,9 @@ def set_xbound(self, lower=None, upper=None):
17691780

17701781
def get_xlim(self):
17711782
"""
1772-
Get the x-axis range as a length 2 attay [*xmin*, *xmax*]
1783+
Get the x-axis range [*xmin*, *xmax*]
17731784
"""
1774-
# # copy of the viewlim array to avoid modify inplace surprises
1775-
return self.viewLim.intervalx.copy()
1785+
return tuple(self.viewLim.intervalx)
17761786

17771787
def set_xlim(self, xmin=None, xmax=None, emit=True, **kwargs):
17781788
"""
@@ -1782,7 +1792,7 @@ def set_xlim(self, xmin=None, xmax=None, emit=True, **kwargs):
17821792
17831793
Set the limits for the xaxis
17841794
1785-
Returns the current xlimits as a length 2 tuple: (*xmin*, *xmax*)
1795+
Returns the current xlimits as a length 2 tuple: [*xmin*, *xmax*]
17861796
17871797
Examples::
17881798
@@ -1943,10 +1953,9 @@ def set_ybound(self, lower=None, upper=None):
19431953

19441954
def get_ylim(self):
19451955
"""
1946-
Get the y-axis range as a length two array [*ymin*, *ymax*]
1956+
Get the y-axis range [*ymin*, *ymax*]
19471957
"""
1948-
# copy of the viewlim array to avoid modify inplace surprises
1949-
return self.viewLim.intervaly.copy()
1958+
return tuple(self.viewLim.intervaly)
19501959

19511960
def set_ylim(self, ymin=None, ymax=None, emit=True, **kwargs):
19521961
"""

0 commit comments

Comments
 (0)