2
我想把子图添加到子图的底部。我得到的问题是,所有第一组子图都想分享他们的X轴,但不是最底层的。当别人做的时候添加一个不共享x轴的子图
channels
是想要共享x轴的子图。
那么如何添加一个不共享x轴的子图呢? 这是我的代码:
def plot(reader, tdata):
'''function to plot the channels'''
channels=[]
for i in reader:
channels.append(i)
fig, ax = plt.subplots(len(channels)+1, sharex=False, figsize=(30,16), squeeze=False)
plot=0
#where j is the channel name
for i, j in enumerate(reader):
y=reader["%s" % j]
ylim=np.ceil(np.nanmax(y))
x=range(len((reader["%s" % j])))
ax[plot,0].plot(y, lw=1, color='b')
ax[plot,0].set_title("%s" % j)
ax[plot,0].set_xlabel('Time/s')
ax[plot,0].set_ylabel('%s' % units[i])
ax[plot,0].set_ylim([np.nanmin(y), ylim+(ylim/100)*10])
plot=plot+1
###here is the new subplot that doesn't want to share the x axis###
ax[plot, 0].plot()
plt.tight_layout()
plt.show()
此代码不工作,因为它们是共享型的最后一个次要情节的x轴。通道长度的变化取决于我在代码中前面指定的内容。
以某种方式使用add_subplot
这是一个有效的选项,尽管我没有固定的频道数量?
非常感谢任何帮助
编辑 图片乔:
当我运行这段代码,规模不会改变绘制的范围内,我的共享轴的比例保持在0.06。我可以给你看一张图片,但不知道在哪里发布。 –
@AshleighClayton - 你可以将它添加到你的问题中,或者只是发布在imgur(或类似的图像共享网站)上,并添加一个链接作为评论。我可能会误解你想要做的事情。 –
我完全抄袭你的代码,只是为了测试它。我会把这个图像放在我的问题中。感谢您的帮助 –