I think the issue here is to connect points in two different axes, which is possible but can be a bit difficult.
In the svn version of matplotlib, there are some helper classes to ease this job a bit. I'm attaching the example. I think you can also run the example with 0.98.5.3. Just download inset_locator.py and modify your import statement. http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/lib/mpl_toolkits/axes_grid/inset_locator.py?revision=7084&view=markup Regards, -JJ On Mon, Jun 29, 2009 at 1:22 PM, Fabrice Silva<si...@lma.cnrs-mrs.fr> wrote: > Le lundi 29 juin 2009 à 14:39 +0200, Fabrice Silva a écrit : >> I merely wanted to add a Polygon patch between the upper and the lower >> subplots, but using data coordinates from these axes. > > One more precision : my intent is to draw a figure 'statically', I do > not need event handling, ie handling manual zoom through an interactive > backend. The figure is generated from a script and directly saved > without human interaction. > -- > Fabrice Silva <si...@lma.cnrs-mrs.fr> > LMA UPR CNRS 7051 > > > ------------------------------------------------------------------------------ > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users >
<<attachment: demo.png>>
""" Demonstrate the use of the BboxPatch, BboxConnector. Note that the example does not work correctly if the figure size changes interactively. """ import matplotlib.pyplot as plt from matplotlib.path import Path from matplotlib.transforms import blended_transform_factory, TransformedBbox from mpl_toolkits.axes_grid.inset_locator import BboxPatch, BboxConnector class BboxConnectorPatch(BboxConnector): def __init__(self, bbox1, bbox2, loc1a, loc2a, loc1b, loc2b, **kwargs): if "transform" in kwargs: raise ValueError("trnasform should nt be set") BboxConnector.__init__(self, bbox1, bbox2, loc1a, loc2a, **kwargs) self.loc1b = loc1b self.loc2b = loc2b def get_path(self): path1 = self.connect_bbox(self.bbox1, self.bbox2, self.loc1, self.loc2) path2 = self.connect_bbox(self.bbox2, self.bbox1, self.loc2b, self.loc1b) path_merged = list(path1.vertices) + list (path2.vertices) + [path1.vertices[0]] return Path(path_merged) if 1: ax1 = plt.subplot(211) ax2 = plt.subplot(212) #def update_transform(fig): # add bbox in upper axes (ax1) tt = ax2.transScale + ax2.transLimits + ax1.transAxes trans = blended_transform_factory(ax1.transData, tt) mybbox = TransformedBbox(ax2.viewLim, trans) bbox_patch = BboxPatch(mybbox, alpha=0.2) ax1.add_patch(bbox_patch) # add connecting lines in lower axes (ax2) patch_props=dict(ec="b", alpha=0.5) # connect lower-left corner (loc1=3) of mybbox to upper-left # corner (loc2=2) of ax2.bbox c1 = BboxConnector(mybbox, ax2.bbox, loc1=3, loc2=2, **patch_props) c1.set_clip_on(False) ax2.add_patch(c1) # connect lower-right corner (loc1=4) of mybbox to upper-right # corner (loc2=1) of ax2.bbox c2 = BboxConnector(mybbox, ax2.bbox, loc1=4, loc2=1, **patch_props) c2.set_clip_on(False) ax2.add_patch(c2) # a polygon patch. p = BboxConnectorPatch(mybbox, ax2.bbox, loc1a=3, loc2a=2, loc1b=4, loc2b=1, fc="b", ec="none", alpha=0.1) p.set_clip_on(False) ax2.add_patch(p) # adjust the xlim ax2.set_xlim(0.3, 0.5) ax1.set_title("try pan/zoom each axes") plt.show()
------------------------------------------------------------------------------
_______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users