python - 如何在连续的 matplotlib 图形之间添加空格?

标签 python python-3.x matplotlib jupyter-lab

如何在 JupyterLab 中的同一个 Jupyter notebook 单元格中的多个图形之间添加空格? 为清楚起见,我不是要在子图之间添加空间,而是要在图形之间添加空间。

例如,

import matplotlib.pyplot as plt

fig1 = plt.figure()
_ = plt.plot(x,y)

fig2 = plt.figure()
_ = plt.hist(z)

将“附加”两个数字,我想在它们之间添加空间,类似于 print('\n') 在打印输出之间添加空间的方式。

为了进一步说明,使用:

import matplotlib.pyplot as plt

fig1 = plt.figure()
_ = plt.plot([1, 2], [2, 3])

print('\n' * 4)

fig2 = plt.figure()
_ = plt.hist([1, 2, 3])

在 JupyterLab 中导致新行被放置在图的前面,而不是之间:

enter image description here

最佳答案

只需添加一个空白图形即可在图形之间创建空间:

import matplotlib.pyplot as plt

fig1 = plt.figure()
_ = plt.plot([1, 2], [2, 3])

f,ax = plt.subplots()
f.set_visible(False)
f.set_figheight(2) # figure height in inches

fig2 = plt.figure()
_ = plt.hist([1, 2, 3])

并用f.set_figheight()控制间距

To produce this figure

关于python - 如何在连续的 matplotlib 图形之间添加空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66265290/

相关文章:

不同 DataFrame 并排的 Pandas 箱线图

python - 如何在仪表板中向 django oscar 产品字段添加附加字段

python - openCV的特征脸

python - 如何在 scikit-learn 中使用正确的 pyprind?

python - 如何从重命名脚本中提取 PDF 文档的标题?

python - 轮廓和轮廓f的使用

python - Microsoft Graph API Nest JSON 请求失败

python - 如何使用python删除xml中的特定标签

python-3.x - 在Python上计算字符串的宽度/高度

python - matplotlib 框架中的 pandas 直方图,具有日期重采样功能