Enforcing common view limits

Hello,

I want to create two sets of axes for a figure that would be equivalent to

ax = fig.add_subplot(111)
ax2 = ax.figure.add_axes(ax.get_position(True),frameon=False,sharex=ax,sharey=ax)

except that I want to be able to specify different tick locators and formatters for ax and ax2. If I remove sharex and sharey, then there is no guarantee that both axes have the same view limits. I want to enforce common view limits while retaining the independence that would allow me to specify different locators/formatters.

I would welcome any advice on how to do this,

Thanks!

Thomas

I've realized that using the ParasiteAxes from the mpl_toolkits should do
exactly what I'm asking. However, I am having a problem with callbacks when
the x and y limits change (try resizing the window). The following script
shows that the callback for the second set of axes is not carried out. Is
this a bug, or a limitation? Or something I'm doing wrong?

Thanks!

Thomas

···

---

import matplotlib.pyplot as mpl
import numpy as np
import mpl_toolkits.axes_grid.parasite_axes as mpl_toolkit

def check_callback(ax):
    print "callback for ",ax.name
    
array = np.random.random((100,100))

fig = mpl.figure()
ax = mpl_toolkit.SubplotHost(fig,1,1,1,adjustable='datalim')

ax.name = "first axis"
ax.callbacks.connect('xlim_changed',check_callback)
ax.callbacks.connect('xlim_changed',check_callback)

ax2 = ax.twin()
ax2.name = "second axis"
ax2.callbacks.connect('ylim_changed',check_callback)
ax2.callbacks.connect('ylim_changed',check_callback)

fig.add_axes(ax)

ax.imshow(array,interpolation='nearest')

fig.canvas.draw()

---

--
View this message in context: http://www.nabble.com/Enforcing-common-view-limits-tp23334325p23348018.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

There was a typo in the script, the callbacks should be

ax.name = "first axis"
ax.callbacks.connect('xlim_changed',check_callback)
ax.callbacks.connect('ylim_changed',check_callback)

ax2 = ax.twin()
ax2.name = "second axis"
ax2.callbacks.connect('xlim_changed',check_callback)
ax2.callbacks.connect('ylim_changed',check_callback)

but the problem remains: check_callback is never called for ax2.

Tom

···

--
View this message in context: http://www.nabble.com/Enforcing-common-view-limits-tp23334325p23348806.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

ax.twin returns a ParasiteAxesAuxTrans instance which is derived from
the mpl's original Axes, but only drawing-related methods are meant to
be meaningful. For example, this axes is never meant to be added to
the figure and the draw method of this axes is never meant to be
called. I haven't looked at it thoroughly but I guess the reason the
callbacks are not processed is because this axes is not added to the
figure and no set_xlim (or set_ylim) is explicitly called.
However, consider it as a feature not a bug.

The xlim of the parasite axes is mean to be "only" changed when the
xlim of the host axes changes. And the set_xlim (and set_ylim) method
should not be called directly on the parasite axes. Furthermore, I
don't see any reason to connect xlim_change event to the parasite
axes. If there is anything you want to do when the xlim of the
parasite axes change, just connect it to the host axes.

If there is a case that xlim_change event should be directly connected
to the parasite axes (instead of the host axes), I'll consider it as a
bug and try to fix it.

Regards,

-JJ

···

On Sat, May 2, 2009 at 2:03 PM, Thomas Robitaille <thomas.robitaille@...287...> wrote:

There was a typo in the script, the callbacks should be

ax.name = "first axis"
ax.callbacks.connect('xlim_changed',check_callback)
ax.callbacks.connect('ylim_changed',check_callback)

ax2 = ax.twin()
ax2.name = "second axis"
ax2.callbacks.connect('xlim_changed',check_callback)
ax2.callbacks.connect('ylim_changed',check_callback)

but the problem remains: check_callback is never called for ax2.

Tom

--
View this message in context: http://www.nabble.com/Enforcing-common-view-limits-tp23334325p23348806.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations
Conference from O'Reilly Media. Velocity features a full day of
expert-led, hands-on workshops and two days of sessions from industry
leaders in dedicated Performance & Operations tracks. Use code vel09scf
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users