@@ -436,8 +436,7 @@ class Axes(martist.Artist):
436
436
}
437
437
438
438
def __str__ (self ):
439
- return "Axes(%g,%g;%gx%g)" % (self ._position [0 ].get (),self ._position [1 ].get (),
440
- self ._position [2 ].get (),self ._position [3 ].get ())
439
+ return "Axes(%g,%g;%gx%g)" % tuple (self ._position .bounds )
441
440
def __init__ (self , fig , rect ,
442
441
axisbg = None , # defaults to rc axes.facecolor
443
442
frameon = True ,
@@ -590,13 +589,13 @@ def sharey_foreign(self, axforeign):
590
589
591
590
def follow_foreign_ylim (ax ):
592
591
ymin , ymax = axforeign .get_ylim ()
593
- # do not emit here or we'll get a ping png effect
592
+ # do not emit here or we'll get a ping pong effect
594
593
self .set_ylim (ymin , ymax , emit = False )
595
594
self .figure .canvas .draw_idle ()
596
595
597
596
def follow_self_ylim (ax ):
598
597
ymin , ymax = self .get_ylim ()
599
- # do not emit here or we'll get a ping png effect
598
+ # do not emit here or we'll get a ping pong effect
600
599
axforeign .set_ylim (ymin , ymax , emit = False )
601
600
axforeign .figure .canvas .draw_idle ()
602
601
@@ -613,65 +612,66 @@ def set_figure(self, fig):
613
612
"""
614
613
martist .Artist .set_figure (self , fig )
615
614
616
- l , b , w , h = self ._position .bounds
617
- xmin = fig .bbox .xmin
618
- xmax = fig .bbox .xmax
619
- ymin = fig .bbox .ymin
620
- ymax = fig .bbox .ymax
621
- figw = xmax - xmin
622
- figh = ymax - ymin
623
- self .left = l * figw
624
- self .bottom = b * figh
625
- self .right = (l + w )* figw
626
- self .top = (b + h )* figh
627
-
628
- self .bbox = maffine .Bbox .from_lbrt (
629
- self .left , self .bottom ,
630
- self .right , self .top ,
631
- )
615
+ self .bbox = maffine .TransformedBbox (self ._position , fig .transFigure )
632
616
#these will be updated later as data is added
633
617
self ._set_lim_and_transforms ()
634
618
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
+
635
629
def _set_lim_and_transforms (self ):
636
630
"""
637
631
set the dataLim and viewLim BBox attributes and the
638
632
transData and transAxes Transformation attributes
639
633
"""
640
- Bbox = maffine .Bbox
634
+ Bbox = maffine .Bbox
635
+ self .viewLim = Bbox .unit ()
636
+
641
637
if self ._sharex is not None :
642
- left = self . _sharex . viewLim . xmin ()
643
- right = self . _sharex . viewLim . xmax ()
644
- else :
645
- left = 0.0
646
- right = 1.0
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
647
643
if self ._sharey is not None :
648
- bottom = self ._sharey .viewLim .ymin ()
649
- top = self ._sharey .viewLim .ymax ()
650
- else :
651
- bottom = 0.0
652
- top = 1.0
644
+ self ._sharey .callbacks .connect (
645
+ 'ylim_changed' , self ._shared_ylim_callback )
646
+ self .viewLim .intervaly = self ._sharex .viewLim .intervaly
653
647
654
- self .viewLim = Bbox .from_lbrt (left , bottom , right , top )
655
648
self .dataLim = Bbox .unit ()
656
649
657
- self .transData = maffine .BboxTransform (
658
- self .viewLim , self .bbox )
659
650
self .transAxes = maffine .BboxTransform (
660
651
Bbox .unit (), self .bbox )
661
652
662
- # MGDTODO
663
- # if self._sharex:
664
- # self.transData.set_funcx(self._sharex.transData.get_funcx())
665
-
666
- # if self._sharey:
667
- # self.transData.set_funcy(self._sharey.transData.get_funcy())
668
-
653
+ localTransData = maffine .BboxTransform (
654
+ self .viewLim , self .bbox )
655
+ if self ._sharex :
656
+ transDataX = self ._sharex .transData
657
+ else :
658
+ transDataX = localTransData
659
+ if self ._sharey :
660
+ transDataY = self ._sharey .transData
661
+ else :
662
+ transDataY = localTransData
663
+ self .transData = localTransData # maffine.blend_xy_sep_transform(transDataX, transDataY)
664
+
665
+
669
666
def get_position (self , original = False ):
670
667
'Return the axes rectangle left, bottom, width, height'
668
+ # MGDTODO: This changed from returning a list to returning a Bbox
669
+ # If you get any errors with the result of this function, please
670
+ # update the calling code
671
671
if original :
672
- return self ._originalPosition . bounds
672
+ return copy . copy ( self ._originalPosition )
673
673
else :
674
- return self ._position . bounds
674
+ return copy . copy ( self ._position )
675
675
# return [val.get() for val in self._position]
676
676
677
677
def set_position (self , pos , which = 'both' ):
@@ -690,14 +690,9 @@ def set_position(self, pos, which='both'):
690
690
ACCEPTS: len(4) sequence of floats
691
691
"""
692
692
if which in ('both' , 'active' ):
693
- # MGDTODO
694
- # # Change values within self._position--don't replace it.
695
- # for num,val in zip(pos, self._position):
696
- # val.set(num)
697
- self ._position .bounds = pos .bounds
698
- # MGDTODO: side-effects
693
+ self ._position .set (pos )
699
694
if which in ('both' , 'original' ):
700
- self ._originalPosition .bounds = pos . bounds
695
+ self ._originalPosition .set ( pos )
701
696
702
697
703
698
def _set_artist_props (self , a ):
@@ -1546,7 +1541,14 @@ def set_xlim(self, xmin=None, xmax=None, emit=True, **kwargs):
1546
1541
xmin , xmax = maffine .nonsingular (xmin , xmax , increasing = False )
1547
1542
1548
1543
self .viewLim .intervalx = (xmin , xmax )
1549
-
1544
+ if emit :
1545
+ self .callbacks .process ('xlim_changed' , self )
1546
+ # MGDTODO: It would be nice to do this is in the above callback list,
1547
+ # but it's difficult to tell how to initialize this at the
1548
+ # right time
1549
+ if self ._sharex :
1550
+ self ._sharex .set_xlim (* self .viewLim .intervalx )
1551
+
1550
1552
return xmin , xmax
1551
1553
1552
1554
def get_xscale (self ):
@@ -1650,7 +1652,6 @@ def set_ylim(self, ymin=None, ymax=None, emit=True, **kwargs):
1650
1652
1651
1653
ACCEPTS: len(2) sequence of floats
1652
1654
"""
1653
-
1654
1655
if ymax is None and iterable (ymin ):
1655
1656
ymin ,ymax = ymin
1656
1657
@@ -1671,8 +1672,14 @@ def set_ylim(self, ymin=None, ymax=None, emit=True, **kwargs):
1671
1672
1672
1673
ymin , ymax = maffine .nonsingular (ymin , ymax , increasing = False )
1673
1674
self .viewLim .intervaly = (ymin , ymax )
1674
- if emit : self .callbacks .process ('ylim_changed' , self )
1675
-
1675
+ if emit :
1676
+ self .callbacks .process ('ylim_changed' , self )
1677
+ # MGDTODO: It would be nice to do this is in the above callback list,
1678
+ # but it's difficult to tell how to initialize this at the
1679
+ # right time
1680
+ if self ._sharey :
1681
+ self ._sharey .set_ylim (* self .viewLim .intervaly )
1682
+
1676
1683
return ymin , ymax
1677
1684
1678
1685
def get_yscale (self ):
0 commit comments