python - 通过多次单击“调整”->“紧密布局”以交互方式使无花果布局更紧密,但无法在我的代码中重现它
问题描述
一件奇怪的事情正在发生。通过多次单击“调整”->“紧密布局”,我在显示绘图后以交互方式更改图形的紧密程度。我知道我可以复制这 6 个参数并使用它们放入我的代码fig.subplots_adjust()
中,但问题是布局发生了变化,但有一点参数没有!所以,我无法重现效果...... 在这里,我将向您展示我的意思:
在我的代码中,我plt.tight_layout()
之前有plt.show()
.
- 这是我得到的结果:
- 现在,我点击“紧凑布局”。参数发生变化,子图看起来更大更近:
- 同样,参数发生变化,子图看起来更大更近:
- 同样,子图更接近但只有一个参数发生了变化,而且变化几乎没有意义 - 顶部是 0.950,现在是 0.951:
- 现在,如果我导出值并放在前面
plt.show()
plt.subplots_adjust(
top=0.95,
bottom=0.062,
left=0.012,
right=0.988,
hspace=0.249,
wspace=0.0)
我得到:
身材没有我想的那么紧!!而且次要情节没有我想要的那么大!!我把完全相同的参数。任何人都知道如何解决它?
重现问题的玩具示例:
import matplotlib.pyplot as plt
limit = 3
fig, axes = plt.subplots(nrows=limit, ncols=limit, sharex=True, sharey=True, )
for i in range(limit):
for j in range(limit):
ax = axes[i, j]
ax.set_xbound(lower=-2, upper=2)
ax.set_ybound(lower=-2, upper=2)
ax.grid()
ax.set_aspect('equal', adjustable='box')
# show
fig = plt.gcf()
fig.canvas.manager.window.showMaximized()
fig.canvas.set_window_title('Test')
plt.tight_layout() # TODO: comment this line to see the difference if tight layout is not specified
# TODO: uncomment the following block to see that nothing happens if tight layout and the parameters are set
# plt.subplots_adjust(
# top=0.951,
# bottom=0.062,
# left=0.012,
# right=0.988,
# hspace=0.249,
# wspace=0.0
# )
plt.show()
旁注:我目前正在使用matplotlib 3.1.1
解决方案
推荐阅读
- python - python中的控制流与字符串
- search - 怎么做 - 数据目录中的通配符搜索(谷歌云平台)
- asp.net-core - blazor-webassembly 上传文件无法显示进度?
- sql - Oracle - 更新两个表之间相同的重复计数
- scala - 有效更新 Ref/MVar
- python - 如何在Django的ManyToMany字段中计算艺术家
- android - Jsoup 属性选择器返回空
- javascript - 如果 li 被禁用,则单击 Ajax 分页
- python - 文件处理程序的 Python 日志记录忽略转义 (\033)
- ruby - Ruby:如何使用方法更改变量的值