matplotlib - 条形图通过方面或轴限制子图内或子图之间的约束删除空间
问题描述
我正在努力删除子图中或子图之间的空白。我已经在这里阅读了很多答案,但我没有得到任何地方。我想用几个子图制作水平条形图:
我的例子是:
import matplotlib.pyplot as plt
x1 = [5]
y1 = [-10]
x2 = [30, 35]
y2 = [-15, -20]
x3 = [15, 5, 20]
y3 = [-10, -15, -30]
xlimits = [-30, 35]
ylimits = [-0.5, 2.5]
fig = plt.figure(figsize=(12,6))
ax1 = fig.add_subplot(3,1,1)
ax1.barh(0, x1, height = 1)
ax1.barh(0, y1, height = 1)
ax2 = fig.add_subplot(3,1,2)
ax2.barh([0, 1], x2, height = 1)
ax2.barh([0, 1], y2, height = 1)
ax3 = fig.add_subplot(3,1,3)
ax3.barh([0, 1, 2], x3, height = 1)
ax3.barh([0, 1, 2], y3, height = 1)
for ax in fig.axes:
ax.set_ylim(ylimits)
ax.set_xlim(xlimits)
plt.show()
我ax.set_ylim(ylimits)
以前所有条的高度都相同,并且ax.set_xlim(xlimits)
在一条垂直线上有“0”。
现在我想调整 bbox 以删除子图中的空白区域(顶部和中间)。但我不知道如何实现这一目标。我也试过了ax.set_aspect()
。在这种情况下,我将收到子图之间的空白空间。我想用子图来轻松添加描述、交换东西等等。
在此先感谢您的任何建议。
解决方案
如果我理解正确,您可以尝试将其添加到您的代码中:
fig.subplots_adjust(wspace=0, hspace=0)
推荐阅读
- firebase - Firebase 在启动期间使用 Flutter 重新进行身份验证
- mysql - 为什么我的右连接和内连接查询在我的 SQL 查询中返回同一个表?
- amazon-web-services - Api 网关与 Lambda 代理集成通过无服务器不解码响应
- node.js - 当手动使用新模型()时,是否可以在保存()之前修改文档,使用猫鼬更新运算符?
- python - Python将列表列表中的数据添加到数据框自己的行中
- python - python map减少具有完全相同元音的单词
- javascript - 当我尝试加载 css 样式表时出现快速 MIME 错误
- sql - 分组连续时间戳(红移)
- python - 使用 aws ssm 执行带有参数的 python 脚本
- python - Python 可执行文件可以创建文件吗?