@@ -436,8 +436,7 @@ class Axes(martist.Artist):
436436 }
437437
438438 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 )
441440 def __init__ (self , fig , rect ,
442441 axisbg = None , # defaults to rc axes.facecolor
443442 frameon = True ,
@@ -590,13 +589,13 @@ def sharey_foreign(self, axforeign):
590589
591590 def follow_foreign_ylim (ax ):
592591 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
594593 self .set_ylim (ymin , ymax , emit = False )
595594 self .figure .canvas .draw_idle ()
596595
597596 def follow_self_ylim (ax ):
598597 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
600599 axforeign .set_ylim (ymin , ymax , emit = False )
601600 axforeign .figure .canvas .draw_idle ()
602601
@@ -613,65 +612,66 @@ def set_figure(self, fig):
613612 """
614613 martist .Artist .set_figure (self , fig )
615614
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 )
632616 #these will be updated later as data is added
633617 self ._set_lim_and_transforms ()
634618
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+
635629 def _set_lim_and_transforms (self ):
636630 """
637631 set the dataLim and viewLim BBox attributes and the
638632 transData and transAxes Transformation attributes
639633 """
640- Bbox = maffine .Bbox
634+ Bbox = maffine .Bbox
635+ self .viewLim = Bbox .unit ()
636+
641637 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
647643 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
653647
654- self .viewLim = Bbox .from_lbrt (left , bottom , right , top )
655648 self .dataLim = Bbox .unit ()
656649
657- self .transData = maffine .BboxTransform (
658- self .viewLim , self .bbox )
659650 self .transAxes = maffine .BboxTransform (
660651 Bbox .unit (), self .bbox )
661652
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+
669666 def get_position (self , original = False ):
670667 '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
671671 if original :
672- return self ._originalPosition . bounds
672+ return copy . copy ( self ._originalPosition )
673673 else :
674- return self ._position . bounds
674+ return copy . copy ( self ._position )
675675 # return [val.get() for val in self._position]
676676
677677 def set_position (self , pos , which = 'both' ):
@@ -690,14 +690,9 @@ def set_position(self, pos, which='both'):
690690 ACCEPTS: len(4) sequence of floats
691691 """
692692 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 )
699694 if which in ('both' , 'original' ):
700- self ._originalPosition .bounds = pos . bounds
695+ self ._originalPosition .set ( pos )
701696
702697
703698 def _set_artist_props (self , a ):
@@ -1546,7 +1541,14 @@ def set_xlim(self, xmin=None, xmax=None, emit=True, **kwargs):
15461541 xmin , xmax = maffine .nonsingular (xmin , xmax , increasing = False )
15471542
15481543 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+
15501552 return xmin , xmax
15511553
15521554 def get_xscale (self ):
@@ -1650,7 +1652,6 @@ def set_ylim(self, ymin=None, ymax=None, emit=True, **kwargs):
16501652
16511653 ACCEPTS: len(2) sequence of floats
16521654 """
1653-
16541655 if ymax is None and iterable (ymin ):
16551656 ymin ,ymax = ymin
16561657
@@ -1671,8 +1672,14 @@ def set_ylim(self, ymin=None, ymax=None, emit=True, **kwargs):
16711672
16721673 ymin , ymax = maffine .nonsingular (ymin , ymax , increasing = False )
16731674 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+
16761683 return ymin , ymax
16771684
16781685 def get_yscale (self ):
0 commit comments