透過程式設計方式停止 Jupyter notebook 中特定影像的互動


若要透過程式設計方式停止 Jupyter notebook 中特定影像的互動,我們可以在此之後使用 plt.off() 停止任何互動。

按順序執行以下命令 −

  • %matplotlib auto
  • import matplotlib.pyplot as plt
  • plt.rcParams["figure.figsize"] = [7.50, 3.50]
  • plt.rcParams["figure.autolayout"] = True
  • 建立一個影像和一組子圖。
  • 在軸上繪製直線(從第 5 步開始)。
  • 關閉互動。
  • 若要顯示該影像,請使用 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 0x7fa6e00f5e48>]

In [6]: plt.ioff()
In [7]: ax.plot([1, 1, 2, 1, 2, 2])
Out[7]: [<matplotlib.lines.Line2D at 0x7fa6e0063ef0>]

In [8]: fig.show()

In [9]:

輸出

更新於: 08-Jul-2021

633 次瀏覽

職業生涯開局

完成課程後獲得認證

開始
廣告
© . All rights reserved.