Aplpy multiplot dynamic axis sharing

こ雲淡風輕ζ 提交于 2019-11-30 07:42:44

问题


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

回答1:


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.


来源:https://stackoverflow.com/questions/42718823/aplpy-multiplot-dynamic-axis-sharing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!