python - 如何更改 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 天刻度?
解决方案
推荐阅读
- javascript - 加载时为 D3 热图单元设置动画?
- c++ - 如何使用函数的输出初始化 const 数组结构字段?
- python - python打印函数中希腊字母的下标问题
- oracle-cloud-infrastructure - Oracle Cloud 始终免费套餐。我有资格吗?
- sql - 无法在 MS Access 的外键字段中插入空值
- python - 尝试将 Dictionary 转换为 DataFrame Pandas 时出现 ValueError
- javascript - 用户输入有时会破坏 REGEX
- sql - Google Big Query:基于当前行条件的聚合新列
- c# - 使用 NoSQL 数据库进行 ASP.NET Core 身份验证
- android - Android Kotlin Coroutine 崩溃,但没有在 Logcat 中报告致命错误