Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python matplotlib与另一个绘图中的yaxis共享xaxis_Python_Matplotlib_Scipy - Fatal编程技术网

Python matplotlib与另一个绘图中的yaxis共享xaxis

Python matplotlib与另一个绘图中的yaxis共享xaxis,python,matplotlib,scipy,Python,Matplotlib,Scipy,如果我想将两个独立轴的x轴和y轴绑在一起,以便它们一起缩放,我通常会这样做: fig = plt.figure() ax1 = fig.add_subplot(121) ax2 = fig.add_subplot(122,sharex=ax1, sharey=ax1) 但我不知道如何将一个地块的坐标轴与另一个地块的坐标轴共享。例如,一个图的X轴是“时间”,我想与另一个图的Y轴分享,Y轴也代表“时间”。类似这样的东西(不起作用…): ax2=fig.add_子批(122,sharex=ax1.y

如果我想将两个独立轴的x轴和y轴绑在一起,以便它们一起缩放,我通常会这样做:

fig = plt.figure()
ax1 = fig.add_subplot(121)
ax2 = fig.add_subplot(122,sharex=ax1, sharey=ax1)
但我不知道如何将一个地块的坐标轴与另一个地块的坐标轴共享。例如,一个图的X轴是“时间”,我想与另一个图的Y轴分享,Y轴也代表“时间”。类似这样的东西(不起作用…):

ax2=fig.add_子批(122,sharex=ax1.yaxis,sharey=ax1.xaxis)


谢谢

通过子地块构造函数共享不会像您所说的那样起作用,但是在创建轴之后,您可以始终使用
get
set
。您可以尝试
ax2.setxlim(ax1.get_ylim())
是否仅在创建子地块时需要此共享,还是在交互式缩放、平移等时也需要此共享?如果用于交互式缩放和平移。我目前正在通过连接到ylim_changed回调:
ax.callbacks.connect('ylim_changed',on_ylims_changed)
来解决这个问题,然后以这种方式更新内容,但似乎有更简单的方法来实现这一点。