我使用以下脚本显示两个y轴和一个公共x轴的信息。你知道吗
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import host_subplot
import mpl_toolkits.axisartist as AA
#creating a host plot with x and y axis
hostplot = host_subplot(111, axes_class=AA.Axes)
#creating a second y axis
extra_y_axis = hostplot.twinx()
extra_y_axis.set_navigate_mode(True)
extra_y_axis.set_navigate(True)
print extra_y_axis.can_zoom() #prints true on output
hostplot.set_xlabel("host_x")
hostplot.set_ylabel("host_y")
extra_y_axis.set_ylabel("extra_y")
hostplot.plot([0, 1, 2], [0, 1, 2])
extra_y_axis.plot([0, 1, 2], [0, 3, 2])
plt.draw()
plt.show()
之后,我使用了左下角托盘中的“缩放到矩形”工具,如下所示:
。你知道吗
我得到了以下结果:
。你知道吗
请注意两张图片中的y轴比例。虽然主机绘图的缩放功能正常工作,但我无法使额外的y轴重新缩放,它始终保持恒定的缩放比例(因此我无法使用第二个轴放大绘图)。你知道吗
如何使所有轴在小范围缩放时重新缩放?你知道吗
谢谢
我把你的问题追溯到axes\u grid1工具箱的问题。如果您不需要使用此工具箱,您可以通过按常规方式初始化图形来轻松解决问题:
如果确实要使用工具箱,则必须添加几条线以使两个y轴一起缩放和变换:
相关问题 更多 >
编程相关推荐