栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Matplotlib / python可点击的点

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Matplotlib / python可点击的点

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

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

import matplotlib.pyplot as pltdef 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]]    printfig, ax = plt.subplots()tolerance = 10 # pointsax.plot(range(10), 'ro-', picker=tolerance)fig.canvas.callbacks.connect('pick_event', on_pick)plt.show()

确切的处理方式取决于您使用的艺术家(换句话说,您使用

ax.plot
vs.
ax.scatter
vs.
ax.imshow
?)。

选择事件将具有不同的属性,具体取决于所选的艺术家。永远存在

event.artist
event.mouseevent
。大多数具有单独元素(例如
Line2D
s
Collections
等)的艺术家将具有被选为的项目索引的列表
event.ind

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



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/648750.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号