matplotlib 的 imshow 中的颜色值?
我想知道在 matplotlib 中使用 imshow() 时单击的点的颜色值。有没有办法通过 matplotlib 中的事件处理程序找到此信息(与单击的 x,y 坐标相同的方式可用)?如果没有,我如何找到这些信息?
具体来说,我正在考虑这样的案例:
imshow(np.random.rand(10,10)*255, interpolation='nearest')
谢谢! ——艾琳
I'd like to know the color value of a point I click on when I use imshow() in matplotlib. Is there a way to find this information through the event handler in matplotlib (the same way as the x,y coordinates of your click are available)? If not, how would I find this information?
Specifically I'm thinking about a case like this:
imshow(np.random.rand(10,10)*255, interpolation='nearest')
Thanks!
--Erin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果“颜色值”指的是图表上单击点处的数组值,那么这很有用。
用法如下:
应该出现一个绘图窗口,单击点,然后返回 numpy 数组的索引。
If by 'color value' you mean the value of the array at a clicked point on a graph, then this is useful.
Usage would be something like:
A plotting window should appear, you click on points, and returned are the indices of the numpy array.
您可以尝试如下操作:
You could try something like the below:
这是一个可行的解决方案。它仅适用于
interpolation = 'nearest'
。我仍在寻找一种更清晰的方法来从图像中检索插值(而不是对选取的 x,y 进行四舍五入并从原始数组中进行选择。)无论如何:Here's a passable solution. It only works for
interpolation = 'nearest'
. I'm still looking for a cleaner way to retrieve the interpolated value from the image (rather than rounding the picked x,y and selecting from the original array.) Anyway:上述解决方案仅适用于单个图像。如果您在同一脚本中绘制两个或多个图像,“inaxes”事件不会在两个轴之间产生差异。您永远不会知道您单击的是哪个轴,因此您不会知道应该显示哪个图像值。
The above solution only works for a single image. If you plot two or more images in the same script, the "inaxes" event will not make a difference between both axis. You will never know in which axis are you clicking, so you won't know which image value should be displayed.