Aplpy multiplot dynamic axis sharing
Asked Answered
C

1

6

Is there any way to make multiplot aplpy plots dynamically share axes so that when one is moved or zoomed, it moves and zooms the others?

I can achieve the affect using matplotlib pyplot's imshow and subplot routines, but using those limits some other important aspects of my plotting, while aplpy provides all the tools I need for my images.

I have tried using the matplotlib cid commands and a function to recenter all the images based on click locations, but I can only zoom in, or out, not both, and I cant click and drag yet.

My MWE of my plotting code is below:

from astropy.io import fits
import matplotlib.pyplot as plt
import aplpy

root = '/my/data/directory/'
data = '3d_image.fits'

hdu = fits.open(root + data)[0]
hdr = hdu.header

fits1 = fits.PrimaryHDU(data = hdu.data[4,:,:], header = hdr)
fits2 = fits.PrimaryHDU(data = hdu.data[6,:,:], header = hdr)

fig = plt.figure(figsize=(15, 15))

f1 = aplpy.FITSFigure(fits1, figure=fig, subplot=[0.1,0.1,0.8,0.35])
f1.show_colorscale(cmap = 'coolwarm', vmin = 8., vmax = 10.5)

f2 = aplpy.FITSFigure(fits2, figure=fig, subplot=[0.1,0.5,0.8,0.35])
f2.show_colorscale(cmap = 'coolwarm', vmin = 1.2, vmax = 1.6)

fig.show
Clothesbasket answered 10/3, 2017 at 12:48 Comment(0)
P
10

It seems that the plotting functionality of aplpy is completely based on matplotlib. So any plot formatting that can be done with aplpy can in one way or the other be done with matplotlib.

But if you still want to stick to aplpy for creating the plots, there should still be a solution which does not need complicated event listeners.

Unfortunately, unlike plotting functionalities of other libraries, aplpy seems to only accept the figure as argument, not the axes.

It should nonetheless be possible to link the axes even after their creation:

axes = fig.get_axes()
axes[0].get_shared_x_axes().join(axes[0], axes[1])
axes[0].get_shared_y_axes().join(axes[0], axes[1])
axes[0].autoscale() # <-- needed if no axes limits are explicitely set.
Phonography answered 10/3, 2017 at 13:29 Comment(1)
Thanks, thats exactly what I needed. I know aplpy uses matplotlib and thus I COULD do things there, but there are several useful aplpy properties that help. For one, dealing with world coordinates is much easier (I dont have to grab them from the header file and extrapolate for example). Another is the autoscaling Beam Size and Scale Bar that change as you zoom in. It seems easier to use aplpy and ask this one question, than use imshow and ask 10 or 20.Clothesbasket

© 2022 - 2024 — McMap. All rights reserved.