如何在單個 IPython 筆記本中多次顯示同一幅 Matplotlib 圖表?


要在單個 iPython 筆記本中多次顯示同一幅 Matplotlib 圖表,我們可以按照以下步驟操作:

  • 設定圖形大小並調整子圖之間和周圍的邊距。
  • 建立一個圖形和一組子圖。
  • 將資料點繪製到該座標軸上。
  • 要再次顯示當前圖形,請使用 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()

輸出

更新於:2021 年 6 月 18 日

已檢視 790 次

開啟你的職業生涯

透過完成課程獲得認證

開始使用
廣告
© . All rights reserved.