Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
451 views
in Technique[技术] by (71.8m points)

python - Aplpy multiplot dynamic axis sharing

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...