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
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.
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.
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:You could try something like the below: