简体   繁体   English

在2D点图上使用鼠标悬停在numpy数组中查找行/位置

[英]Finding the row/position in a numpy array using a mouse over on a 2D dot plot

I have a 2D dot plot which I generated using matplotlib with 750 points on it. 我有一个使用matplotlib生成的2D点图,上面有750个点。 I was trying to use mpldatacursor so that I can mouse over the points to determine the label for a datapoint (ie row/position in the numpy array etc). 我试图使用mpldatacursor,以便我可以将鼠标悬停在这些点上以确定数据点的标签(即numpy数组中的行/位置等)。

When I use mpldatacursor it works well - but I only get x & y co-ords. 当我使用mpldatacursor时,它可以很好地工作-但我只能得到x和y坐标。 Any thoughts on how I might find the label/origin of the individual points of interest? 关于如何找到各个兴趣点的标签/起源有任何想法吗? I know I could plot labels - but with 750 datapoints it's pretty messy. 我知道我可以绘制标签-但是有750个数据点,非常混乱。

thoughts, Sarr. 想法,萨尔。

You could pick a plotted point, passing the information back in data coordinates. 您可以选择一个绘制点,将信息传递回数据坐标中。 Check matplotlib's event handling and picking guide for detailed information on how to achieve this. 查看matplotlib的事件处理和选择指南,以获取有关如何实现此目的的详细信息。

Once you have the data coordinates, you can find the corresponding indices using numpy: 一旦有了数据坐标,就可以使用numpy查找相应的索引:

import numpy as np

# arr is the array you plot

[...code to plot/pick array...]

# datapt are the data coordinates you get back from the picking event

indices = np.argwhere(arr == datapt)

This approach involves a lot more work than mpldatacursor, but the latter doesn't seem to offer nearly as much flexibility. 这种方法比mpldatacursor涉及更多的工作,但是后者似乎并没有提供那么多的灵活性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM