python - tight_layout() 不考虑数字字幕

如果我在我的 matplotlib 图中添加了一个副标题,它会被副图的标题覆盖。有人知道如何轻松解决这个问题吗?我尝试了 tight_layout() 函数,但它只会让事情变得更糟。

例子:

import numpy as np
import matplotlib.pyplot as plt

f = np.random.random(100)
g = np.random.random(100)
fig = plt.figure()
fig.suptitle('Long Suptitle', fontsize=24)
plt.subplot(121)
plt.plot(f)
plt.title('Very Long Title 1', fontsize=20)
plt.subplot(122)
plt.plot(g)
plt.title('Very Long Title 2', fontsize=20)
plt.tight_layout()
plt.show()

最佳答案

您可以在非常 tight_layout 调用中调整子图几何,如下所示:

fig.tight_layout(rect=[0, 0.03, 1, 0.95])

正如文档 (https://matplotlib.org/users/tight_layout_guide.html) 中所述:

tight_layout() only considers ticklabels, axis labels, and titles. Thus, other artists may be clipped and also may overlap.

https://stackoverflow.com/questions/8248467/

相关文章:

linux - 比较 Unix/Linux IPC

python - 是否可以将另一个版本的 Python 安装到 Virtualenv?

linux - 在 LINUX 中确定 .a 库/存档是 32 位还是 64 位?

linux - 多个 GZip 文件的快速连接

python - 如何在Python中检查两个列表是否循环相同

linux - 如何将我的密码更改为符号链接(symbolic link)目录的真实路径?

c - 什么是 vdso 和 vsyscall?

python - 通过 'ElementTree' 在 Python 中使用命名空间解析 XML

python - 是否可以按降序使用 argsort?

python - 为什么会发生这个 UnboundLocalError(关闭)?