【发布时间】:2013-11-20 11:47:38
【问题描述】:
我正在尝试在子图的底部添加一个子图。我遇到的问题是所有第一组子图都希望共享它们的 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 是否是一个有效的选择,即使我没有固定数量的频道?
非常感谢您的帮助
编辑 乔的形象:
【问题讨论】:
标签: python matplotlib subplot