如何在 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 中导致新行被放置在图的前面,而不是之间:
最佳答案
只需添加一个空白图形即可在图形之间创建空间:
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()
控制间距
关于python - 如何在连续的 matplotlib 图形之间添加空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66265290/