how to get xlims after zooming

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.

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.

Regards,

Maximilian

···

--
View this message in context: http://www.nabble.com/how-to-get-xlims-after-zooming-tp21205310p21205310.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Why not using the 'sharex' keywork argument of subplot function?
from matplotlib.pyplot import subplot
S1 = subplot(311)
S2 = subplot(312, sharex=S1)
S3 = subplot(313, sharex=S1)
S1, S2 and S3 will share the same x-range.

···

Le lundi 29 décembre 2008 à 08:17 -0800, mfabulous a écrit :

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.

--
Fabrice Silva <silva@...1918...>
LMA UPR CNRS 7051 - équipe S2M

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

···

On Mon, Dec 29, 2008 at 10:17 AM, mfabulous <mxhf@...361...> wrote:

Excellent, thank you, this is exactly what I was looking for!

Regards,

Maximilian

···

--
View this message in context: http://www.nabble.com/how-to-get-xlims-after-zooming-tp21205310p21206768.html
Sent from the matplotlib - users mailing list archive at Nabble.com.