matplotlib-以交互方式选择点或位置? [英] matplotlib -- interactively select points or locations?

查看:40
本文介绍了matplotlib-以交互方式选择点或位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在R中,有一个函数locator,它类似于Matlab的ginput,您可以用鼠标单击图形并选择任何x,y坐标.此外,还有一个叫做 identify(x,y) 的函数,如果你给它一组你绘制的点 x,y 然后点击图形,它会返回的索引最接近(在可调整的公差范围内)您选择的位置(或多个索引,如果选择了多个点)的x,y点.Matplotlib中有这样的功能吗?

In R, there is a function locator which is like Matlab's ginput where you can click on the figure with a mouse and select any x,y coordinate. In addition, there is a function called identify(x,y) where if you give it a set of points x,y that you have plotted and then click on the figure, it will return the index of the x,y point which lies nearest (within an adjustable tolerance) to the location you have selected (or multiple indices, if multiple points are selected). Is there such a functionality in Matplotlib?

推荐答案

您可能想使用 pick事件:

fig = figure()
ax1 = fig.add_subplot(111)
ax1.set_title('custom picker for line data')
line, = ax1.plot(rand(100), rand(100), 'o', picker=line_picker)
fig.canvas.mpl_connect('pick_event', onpick2)

在此处通过选择器参数设置的公差:

Tolerance set by picker parameter there:

line, = ax1.plot(rand(100), 'o', picker=5)  # 5 points tolerance

这篇关于matplotlib-以交互方式选择点或位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆