您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Matplotlib / python可点击的点

Matplotlib / python可点击的点

要扩展@tcaswell所说的内容,请参见此处的文档:http://matplotlib.org/users/event_handling.html

但是,您可能会发现选择事件的快速演示很有用:

import matplotlib.pyplot as plt

def on_pick(event):
    artist = event.artist
    xmouse, ymouse = event.mouseevent.xdata, event.mouseevent.ydata
    x, y = artist.get_xdata(), artist.get_ydata()
    ind = event.ind
    print 'Artist picked:', event.artist
    print '{} vertices picked'.format(len(ind))
    print 'Pick between vertices {} and {}'.format(min(ind), max(ind)+1)
    print 'x, y of mouse: {:.2f},{:.2f}'.format(xmouse, ymouse)
    print 'Data point:', x[ind[0]], y[ind[0]]
    print

fig, ax = plt.subplots()

tolerance = 10 # points
ax.plot(range(10), 'ro-', picker=tolerance)

fig.canvas.callbacks.connect('pick_event', on_pick)

plt.show()

确切的处理方式取决于您使用的艺术家(换句话说,您使用ax.plotvs. ax.scattervs. ax.imshow?)。

选择事件将具有不同的属性,具体取决于所选的艺术家。永远存在event.artistevent.mouseevent。大多数具有单独元素(例如Line2DsCollections等)的艺术家将具有被选为的项目索引的列表event.ind

如果您想绘制多边形并在其中选择点,请参见:http ://matplotlib.org/examples/event_handling/lasso_demo.html#event-handling- example-code-lasso-demo- py

python 2022/1/1 18:42:38 有273人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶