首页 > 解决方案 > 如何更改 matplotlib 图表中两个刻度之间的间距?

问题描述

我正在绘制一些需要第 0 天不在 x 轴上显示的数据。数据框没有第 0 天的列,但 Matplotlib 在第 -1 天和第 1 天之间为其创建了一个空间。我查看了文档,但找不到调整两个刻度之间间距的方法。数据框是:

group  stat   -1.0        1.0       2.0        3.0        4.0       5.0
abc    mean    8.362999  17.043362  3.526539  22.931884  10.835121  6.035011
abc     sem    1.481135   5.029173  0.822778  13.768812   2.149704  0.840965
abc     std    3.311919  11.245573  1.839788  30.787999   4.806885  1.880455

绘制代码:

df.set_index(['subject'], inplace=True)
df.drop(['group'],axis=1,inplace=True)
x = df.columns.values
y = df.loc['mean'].values
sem = df.loc['sem'].values
plt.errorbar(x, y, sem, color='#0075d9', marker='o', clip_on=False)

这是图表的一个示例(请忽略阴影): 在此处输入图像描述 您可以看到它在 -1 和 1 之间比其他刻度有更多的空间。有没有办法从 X 轴“删除”第 0 天刻度?

标签: pythonmatplotlib

解决方案


推荐阅读