@@ -435,6 +435,9 @@ class Axes(martist.Artist):
435
435
1 : 'log' ,
436
436
}
437
437
438
+ _shared_x_axes = cbook .Grouper ()
439
+ _shared_y_axes = cbook .Grouper ()
440
+
438
441
def __str__ (self ):
439
442
return "Axes(%g,%g;%gx%g)" % tuple (self ._position .bounds )
440
443
def __init__ (self , fig , rect ,
@@ -491,6 +494,10 @@ def __init__(self, fig, rect,
491
494
# must be set before set_figure
492
495
self ._sharex = sharex
493
496
self ._sharey = sharey
497
+ if sharex is not None :
498
+ self ._shared_x_axes .join (self , sharex )
499
+ if sharey is not None :
500
+ self ._shared_y_axes .join (self , sharey )
494
501
# Flag: True if some other Axes instance is sharing our x or y axis
495
502
self ._masterx = False
496
503
self ._mastery = False
@@ -502,7 +509,6 @@ def __init__(self, fig, rect,
502
509
# this call may differ for non-sep axes, eg polar
503
510
self ._init_axis ()
504
511
505
-
506
512
if axisbg is None : axisbg = rcParams ['axes.facecolor' ]
507
513
self ._axisbg = axisbg
508
514
self ._frameon = frameon
@@ -616,55 +622,28 @@ def set_figure(self, fig):
616
622
#these will be updated later as data is added
617
623
self ._set_lim_and_transforms ()
618
624
619
- def _shared_xlim_callback (self , ax ):
620
- xmin , xmax = ax .get_xlim ()
621
- self .set_xlim (xmin , xmax , emit = False )
622
- self .figure .canvas .draw_idle ()
623
-
624
- def _shared_ylim_callback (self , ax ):
625
- ymin , ymax = ax .get_ylim ()
626
- self .set_ylim (ymin , ymax , emit = False )
627
- self .figure .canvas .draw_idle ()
628
-
629
625
def _set_lim_and_transforms (self ):
630
626
"""
631
627
set the dataLim and viewLim BBox attributes and the
632
628
transData and transAxes Transformation attributes
633
629
"""
634
- Bbox = mtransforms .Bbox
635
- self .viewLim = Bbox .unit ()
636
-
637
- if self ._sharex is not None :
638
- # MGDTODO: This may be doing at least one too many updates
639
- # than necessary
640
- self ._sharex .callbacks .connect (
641
- 'xlim_changed' , self ._shared_xlim_callback )
642
- self .viewLim .intervalx = self ._sharex .viewLim .intervalx
643
- if self ._sharey is not None :
644
- self ._sharey .callbacks .connect (
645
- 'ylim_changed' , self ._shared_ylim_callback )
646
- self .viewLim .intervaly = self ._sharex .viewLim .intervaly
647
-
648
- self .dataLim = Bbox .unit ()
630
+ self .viewLim = mtransforms .Bbox .unit ()
631
+ self .dataLim = mtransforms .Bbox .unit ()
649
632
650
633
self .transAxes = mtransforms .BboxTransform (
651
- Bbox .unit (), self .bbox )
652
-
634
+ mtransforms .Bbox .unit (), self .bbox )
653
635
self .transData = mtransforms .BboxTransform (
654
636
self .viewLim , self .bbox )
655
637
656
638
657
639
def get_position (self , original = False ):
658
640
'Return the axes rectangle left, bottom, width, height'
659
- # MGDTODO: This changed from returning a list to returning a Bbox
660
- # If you get any errors with the result of this function, please
661
- # update the calling code
662
641
if original :
663
- return copy . copy ( self ._originalPosition )
642
+ return self ._originalPosition
664
643
else :
665
- return copy .copy (self ._position )
666
- # return [val.get() for val in self._position]
644
+ return self ._position
667
645
646
+
668
647
def set_position (self , pos , which = 'both' ):
669
648
"""
670
649
Set the axes position with pos = [left, bottom, width, height]
@@ -699,8 +678,7 @@ def cla(self):
699
678
self .xaxis .cla ()
700
679
self .yaxis .cla ()
701
680
702
- # MGDTODO
703
- # self.dataLim.ignore(1)
681
+ self .ignore_existing_data_limits = True
704
682
self .callbacks = cbook .CallbackRegistry (('xlim_changed' , 'ylim_changed' ))
705
683
706
684
if self ._sharex is not None :
@@ -886,7 +864,7 @@ def apply_aspect(self, data_ratio = None):
886
864
return
887
865
888
866
889
- l ,b ,w ,h = self .get_position (original = True )
867
+ l ,b ,w ,h = self .get_position (original = True ). bounds
890
868
box_aspect = fig_aspect * (h / w )
891
869
data_ratio = box_aspect / A
892
870
@@ -1152,7 +1130,7 @@ def update_datalim(self, xys):
1152
1130
# Otherwise, it will compute the bounds of it's current data
1153
1131
# and the data in xydata
1154
1132
xys = npy .asarray (xys )
1155
- self .dataLim . update_numerix_xy (xys , - 1 )
1133
+ self .update_datalim_numerix (xys [:, 0 ], xys [:, 1 ] )
1156
1134
1157
1135
1158
1136
def update_datalim_numerix (self , x , y ):
@@ -1161,10 +1139,9 @@ def update_datalim_numerix(self, x, y):
1161
1139
# limits and set the bound to be the bounds of the xydata.
1162
1140
# Otherwise, it will compute the bounds of it's current data
1163
1141
# and the data in xydata
1164
- #print type(x), type(y)
1165
- # MGDTODO
1166
1142
## self.dataLim.update_numerix(x, y, -1)
1167
- self .dataLim .update_from_data (x , y )
1143
+ self .dataLim .update_from_data (x , y , self .ignore_existing_data_limits )
1144
+ self .ignore_existing_data_limits = False
1168
1145
1169
1146
def _get_verts_in_data_coords (self , trans , xys ):
1170
1147
if trans == self .transData :
@@ -1264,9 +1241,7 @@ def draw(self, renderer=None, inframe=False):
1264
1241
if not self .get_visible (): return
1265
1242
renderer .open_group ('axes' )
1266
1243
self .apply_aspect ()
1267
- # MGDTODO -- this is where we can finalize all of the transforms
1268
- # self.transData.freeze() # eval the lazy objects
1269
- # self.transAxes.freeze()
1244
+
1270
1245
if self .axison and self ._frameon : self .axesPatch .draw (renderer )
1271
1246
artists = []
1272
1247
@@ -1314,17 +1289,13 @@ def draw(self, renderer=None, inframe=False):
1314
1289
if self .axison and self ._frameon :
1315
1290
artists .append (self .axesFrame )
1316
1291
1317
- # keep track of i to guarantee stable sort for python 2.2
1318
- dsu = [ (a .zorder , i , a ) for i , a in enumerate (artists )
1319
- if not a .get_animated ()]
1292
+ dsu = [ (a .zorder , a ) for a in artists
1293
+ if not a .get_animated () ]
1320
1294
dsu .sort ()
1321
1295
1322
- for zorder , i , a in dsu :
1296
+ for zorder , a in dsu :
1323
1297
a .draw (renderer )
1324
1298
1325
- # MGDTODO
1326
- # self.transData.thaw() # release the lazy objects
1327
- # self.transAxes.thaw() # release the lazy objects
1328
1299
renderer .close_group ('axes' )
1329
1300
self ._cachedRenderer = renderer
1330
1301
@@ -1509,7 +1480,6 @@ def set_xlim(self, xmin=None, xmax=None, emit=True, **kwargs):
1509
1480
1510
1481
ACCEPTS: len(2) sequence of floats
1511
1482
"""
1512
-
1513
1483
if xmax is None and iterable (xmin ):
1514
1484
xmin ,xmax = xmin
1515
1485
@@ -1534,11 +1504,10 @@ def set_xlim(self, xmin=None, xmax=None, emit=True, **kwargs):
1534
1504
self .viewLim .intervalx = (xmin , xmax )
1535
1505
if emit :
1536
1506
self .callbacks .process ('xlim_changed' , self )
1537
- # MGDTODO: It would be nice to do this is in the above callback list,
1538
- # but it's difficult to tell how to initialize this at the
1539
- # right time
1540
- if self ._sharex :
1541
- self ._sharex .set_xlim (* self .viewLim .intervalx )
1507
+ # Call all of the other x-axes that are shared with this one
1508
+ for other in self ._shared_x_axes .get_siblings (self ):
1509
+ if other is not self :
1510
+ other .set_xlim (self .viewLim .xmin , self .viewLim .xmax , emit = False )
1542
1511
1543
1512
return xmin , xmax
1544
1513
@@ -1665,11 +1634,10 @@ def set_ylim(self, ymin=None, ymax=None, emit=True, **kwargs):
1665
1634
self .viewLim .intervaly = (ymin , ymax )
1666
1635
if emit :
1667
1636
self .callbacks .process ('ylim_changed' , self )
1668
- # MGDTODO: It would be nice to do this is in the above callback list,
1669
- # but it's difficult to tell how to initialize this at the
1670
- # right time
1671
- if self ._sharey :
1672
- self ._sharey .set_ylim (* self .viewLim .intervaly )
1637
+ # Call all of the other y-axes that are shared with this one
1638
+ for other in self ._shared_y_axes .get_siblings (self ):
1639
+ if other is not self :
1640
+ other .set_ylim (self .viewLim .ymin , self .viewLim .ymax , emit = False )
1673
1641
1674
1642
return ymin , ymax
1675
1643
0 commit comments