在单个IPython笔记本中如何显示同一Matplotlib图形多次?
要在单个iPython笔记本中多次显示同一Matplotlib图形,我们可以执行以下步骤 –
- 设置子图之间和周围的填充并调整图形大小。
- 创建一个figure和一组subplot。
- 在该轴上绘制数据点。
- 要再次显示当前图,请使用 fig.show() 方法。
例子
In [1]: %matplotlib auto
Using matplotlib backend: Qt5Agg
In [2]: import matplotlib.pyplot as plt
In [3]: plt.rcParams["figure.figsize"] = [7.50, 3.50]
...: plt.rcParams["figure.autolayout"] = True
In [4]: fig, ax = plt.subplots()
In [5]: ax.plot([2, 4, 7, 5, 4, 1])
Out[5]: [<matplotlib.lines.Line2D at 0x7f4270361c50>]
In [6]: fig.show()