How can I extract the x and y coordinates when hovering over a "heatmap"?
10 views (last 30 days)
Show older comments
MathWorks Support Team
on 13 Apr 2020
Answered: MathWorks Support Team
on 27 Apr 2020
I am using a "heatmap" object and I would like to be able to select one cell and be able to get the position of it, through code, not only by reading it from the dataTips window. Is there a property or a callback which allows me to do that?
Accepted Answer
MathWorks Support Team
on 13 Apr 2020
As of MATLAB R2019b, this is not possible. Other objects such as "imagesc" allow the exact functionality that you require. In fact, you can use their "ButtonDownFcn" method to extract the coordinates of the point where you click in the figure. Therefore, as a workaround, you could use the following script to create an image object which looks like a "heatmap" and extract the position of the mouse:
d = magic(5);
im = imagesc(d);
[x,y] = meshgrid(1:5);
labels = num2str(d(:));
text(x(:),y(:),labels);
im.ButtonDownFcn = @(s,e) disp(e)
0 Comments
More Answers (0)
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!