第一步: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
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与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