第一步:https://matplotlib.org/tutorials/introductory/usage.html#sphx-glr-tutorials-introductory-usage-py
看這個了解大概的matplotlib使用的背景架構:基于函數程式設計與基于對象程式設計的差別:
Figure, Axes, Axis, Tick,Canvas之間的關系是什麼?
Backend主要包含的FigureCanvas 與 Renderer分别可以表現為畫布和畫筆,而Artist就是實作畫筆與畫布之間連接配接的橋梁?
了解什麼是互動式,什麼是非互動式,如何将screen置于前段進行顯示?

第二步:https://matplotlib.org/2.0.0/users/artists.html#object-containers
了解各個Artist之間如何實作互相引用,他們的Property有哪些?如何用get與set函數調用檢視這些Property。
以及Container Artist主要包含的attributes有哪些?
對于figure 來說:
fig.axes, fig.images; fig.lines, fig.texts, fig,legends 都是在一個list裡面,fig.axes是一個包含container的list,其他的都是primitive的list。fig.patch 是一個背景對象,由于一個figure隻有一個背景,是以它不是list
對于Axes來說:
包含的primitive對象和figure一緻,隻是多出兩個xaxis與yaxis對象。
Axes的核心是有很多helper function,輔助axes來建構primitive artist:如plot(),scatter(),bar()等,并且把他們存入到Axes中。可以通過axes.lines, axes.collections, axis.patches等來直接調用。當時要注意:它們都是list,要使用循環來對其中每個對象操作,比如:
fig = plt.figure()
ax = fig.add_subplot(111)
rects = ax.bar(range(10), 20*np.random.rand(10))
drs = []
for rect in rects:
dr = DraggableRectangle(rect)
#DraggableRectangle是一個自定義函數,對bar中每一個柱形進行操作。
第三步:https://matplotlib.org/users/event_handling.html
學習event,互動式操作
MouseEvent | 'button_press_event' | 滑鼠點選 |
'button_release_event' | 滑鼠釋放 | |
'motion_notify_event' | 滑鼠滑動 | |
'scroll_event' | 滑鼠滑輪滑動 | |
KeyEvent | 'key_press_event' | 鍵盤按下 |
'key_release_event' | 鍵盤釋放 | |
PickEvent | 'pick_event' | Figure的canvas被選取 |
LocationEvent | 'figure_enter_event' | 滑鼠進入figure |
'figure_leave_event' | 滑鼠離開figure | |
'axes_enter_event' | 滑鼠進入axes | |
'axes_leave_event' | 滑鼠離開axes |
MouseEvent與KeyEvent從LocationEvent中派生而來,是以三者都具有如下屬性:
event.x,event.y 擷取像素坐标
event.xdata,event.ydata 擷取坐标軸内坐标
event.inaxes 如果滑鼠在axes上則傳回axes對象執行個體
對于LocationEvent,它還具有如下屬性:
event.button 表示使用了滑鼠的左中右3個按鍵,已經轉珠的上下兩個按鍵
event.key 表示使用了鍵盤的哪個按鍵
對于PickEvent,具有如下屬性:
event.artist 表示被mouse選中的對象
event.mouseevent.xdata 用這種方式來繼承MouseEvent的屬性
使用Event編碼遇到的小問題記錄:
1,event.button(),由于是函數,是以有(),并且有傳回值,分别是1,2,3分别表示左鍵,滑輪鍵,右鍵。
2,fig.canvas.mpl_connect(),表示在fig這個figure對象下的畫布canvas,要實作一個擷取connection的ID的功能。調用的函數是mpl_connect().是以經常有使用ax.figure來表示在ax這個axes下的figure;再使用ax.figure.canvas表示這個figure下的畫布canvas。
3, 在互動模式下:plt.show()是不需要的;
在block模式下,plt.show()是需要的
參考文獻:
1. https://matplotlib.org/tutorials/introductory/usage.html#sphx-glr-tutorials-introductory-usage-py
2. https://matplotlib.org/2.0.0/users/artists.html#object-containers
3. https://matplotlib.org/users/event_handling.html