透過 Python Matplotlib 對互動式繪圖進行命令列操作


要獲取互動式繪圖,我們需要啟用圖形。使用 plt.ioff()plt.ion(),我們可以使用繪圖執行互動式操作。

開啟 Ipython shell,並在 shell 中輸入以下命令。

示例

In [1]: %matplotlib auto
Using matplotlib backend: GTK3Agg

In [2]: import matplotlib.pyplot as

In [3]: fig, ax = plt.subplots() # Diagram will pop up. Let’s interact.

In [4]: ln, = ax.plot(range(5))  # Drawing a line

In [5]: ln.set_color("orange")   # Changing drawn line to orange

In [6]: plt.ioff() # Stopped interaction

In [7]: ln.set_color("red")
# Since we have stopped the interaction in the last step

In [8]: plt.ion() # Started interaction

輸出

更新時間: 03-Jun-2021

1K+ 瀏覽次數

開啟你的職業生涯

完成課程認證

開始
廣告
© . All rights reserved.