|
matplotlib应该可以做到你的要求
参考: Dream__TT的博客:python中Matplotlib库显示界面中进行鼠标交互绘制操作 (百度到的,网址在下面,论坛要审核网址,比较慢,所以截图的)
下面代码是根据这个博客的内容整理的,实测可以实现鼠标交互,他的有点点乱,貌似也是从那个地方复制粘贴的,当然这个代码肯定不满足你的要求,不过可以参考,你就自己去实现了
- #coding=utf-8
- import matplotlib.pylab as plt
- import numpy as np
- def OnClick(event):
- global Coords1x,Coords1y
- global Coords3x,Coords3y
- #ax = plt.gca()
- if event.button ==1:
- Coords1x = event.xdata
- Coords1y = event.ydata
- if event.button == 3:
- Coords3x = event.xdata
- Coords3y = event.ydata
- def OnMouseMotion(event):
- global Coords2x,Coords2y,x1,y1
- if event.button == 1:
- Coords2x = event.xdata
- Coords2y = event.ydata
- x1 = [Coords1x,Coords2x]
- y1 = [Coords1y,Coords2y]
- ax = plt.gca()
- lines = ax.plot(x1,y1,picker = 20)
- ax.figure.canvas.draw()
- #删除之前的线条,进行更新
- l = lines.pop(0)
- l.remove()
- del l
- elif event.button == 3:
- Coords4x = event.xdata
- Coords4y = event.ydata
- x2 = [Coords3x,Coords4x]
- y2 = [Coords3y,Coords4y]
- ax1 = plt.gca()
- #lines = ax1.plot(x1,y1,picker = 5)
- lines1 = ax1.plot(x2,y2,picker = 20)
- ax1.figure.canvas.draw()
- #删除之前的线条,进行更新
- l = lines1.pop(0)
- l.remove()
- del l
- fig = plt.figure(dpi=120)
- fig.canvas.mpl_connect('button_press_event',OnClick)
- fig.canvas.mpl_connect('motion_notify_event',OnMouseMotion)
- fig.show()
复制代码
|
|