On Mon, Dec 29, 2008 at 10:17 AM, mfabulous <m...@gmx.net> wrote:
>
> Hi,
>
> I apologize if this was asked before.
>
> I am trying to implement of a zoom lock over multiple subplots. I.e. I have
> four subplots where the xaxis stretches from some value xmin to some xmax.
> The range is the same for all four plots. Now if the user zooms into a
> different range in one of the four plots, I want to update the ranges of the
> other plots.

The best way to do this is to use shared axis

  ax1 = subplot(211)
  ax2 = subplot(212, sharex=ax1)

Then when you zoom in one, the xaxis in the other will be updated too.

>
> Something like:
> def onzoom():
>  xmin, xmax = ZOOMED_PLOT.xlims()
>  for SUBPLOTS_1-4:
>   xlims(xmin, xmax)
>
> Now, I know how to update the xrange of an existing plot. But I do not know
> how to read the modified xrange after an interactive (e.g. rectangle) zoom.
> It seems to me that xlims() does not return the updated limits?
>
> Also, while I was able to work around this: Is there A way to directly react
> to a zoom event. Currently I caputre the mouse-button-released event, then
> try to check all ranges to figure out which one changed (which I actually
> don't know how to do due to my above mentioned problem) and update all
> ranges.

You can connect to the xlim_changed event::

  ax1 = subplot(211)

  def onchanged(ax):
      print ax.get_xlim()

  ax1.connect('xlim_changed', onchanged)

But using shared axes as described above is the way to go.

JDH

------------------------------------------------------------------------------
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to