简体   繁体   English

Aplpy多色动态轴共享

[英]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? 是否有任何方法可以使多点aplpy图动态共享轴,以便在移动或缩放时,它会移动并缩放其他轴?

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. 我可以使用matplotlib pyplot的imshow和subplot例程来实现这些效果,但是使用这些可以限制我的绘图的其他一些重要方面,而aplpy提供了我的图像所需的所有工具。

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. 我已经尝试使用matplotlib cid命令和一个函数来根据点击位置重新定位所有图像,但我只能放大或缩小,而不是两者,我无法点击并拖动。

My MWE of my plotting code is below: 我的绘图代码的MWE如下:

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

It seems that the plotting functionality of aplpy is completely based on matplotlib. 似乎aplpy的绘图功能完全基于matplotlib。 So any plot formatting that can be done with aplpy can in one way or the other be done with matplotlib. 因此,任何可以用aplpy完成的绘图格式都可以通过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. 但是,如果您仍然希望坚持使用aplpy来创建绘图,那么仍然应该有一个不需要复杂事件侦听器的解决方案。

Unfortunately, unlike plotting functionalities of other libraries, aplpy seems to only accept the figure as argument, not the axes. 不幸的是,与绘制其他库的功能不同,aplpy似乎只接受数字作为参数,而不是轴。

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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM