【发布时间】:2020-06-11 21:49:36
【问题描述】:
我在一个图中绘制了 8 个子图,如下所示:
import matplotlib.pyplot as plt
fig, axs = plt.subplots(8,sharex="col" )
label = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
data = [0.6, 0.4, 1.3, 0.8, 0.9, 1.0, 1.6, 0.2]
plt.xlim(0,2)
for i in range(8):
axs[i].set_xlim([0, 2])
axs[i].axvline(data[i],linestyle='--')
axs[i].set_yticks(())
axs[i].set_ylabel(label[i], rotation=0, ha='right', va='center')
axs[7].tick_params(axis='x', direction='out')
plt.show()
除了 x 轴上没有刻度外,一切正常。我做错了什么?
【问题讨论】:
-
matplotlib 2.2.2对我来说很好用。也许试试sharex=True我看不出它不适合你的原因。尝试重新启动内核 -
也在 3.0.2 上为我工作。在导入
pyplot之前使用agg非交互式后端(import matplotlib; matplotlib.use('Agg'),然后使用plt.savefig(filename)而不是plt.show(),您是否得到相同的结果?想知道是否是您的X 显示器以某种方式导致了问题。 -
使用 3.1.3。
-
这是在带有 %matplotlib qt 的 Jupyter 笔记本中。你能重现吗? @Sheldore
-
我在 jupyter 中尝试了 qt,它在新窗口中打开了一个图,我仍然可以看到刻度
标签: python matplotlib