如何在 Spyder/Ipython/matplotlib 中重新獲取互動式繪圖?
要獲得互動式繪圖,我們需要啟用圖形。使用 plt.ioff() 和 plt.ion(),我們可以對繪圖執行互動式操作。
步驟
使用子圖方法建立 fig 和 ax 變數,其中預設 nrows 和 ncols 為 1。
使用 plot() 方法繪製一條線。
設定線條的顏色,即橙色。
使用 plt.ioff() 方法停止互動。
要製作互動式繪圖,請更改線條座標的顏色。
使用 plt.ion() 方法開始互動。
示例
在 Ipython 中使用互動式繪圖 -
In [1]: %matplotlib auto
Using matplotlib backend: GTK3Agg
In [2]: import matplotlib.pyplot as plt
In [3]: fig, ax = plt.subplots() # Diagram will get popped 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('green')
# Since we have stopped the interaction in the last step
In [8]: plt.ion() # Started interaction輸出

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP