Display information about a point by hovering over it on a figure

64 次查看(过去 30 天)
I have a matrix with columns for latitude, longitude, temperature, elevation, site number. In the rows I have 200 sites. I plot the sites on a map (y-axis=latitude, x-axis=longitude).
What I want to then be able to do is hover my mouse over a given point and have a small box display the other relevant information about the point (temperature, elevation, site number).
I remember seeing this on a Matlab forum in the past but I cannot for the life of me find the solution. I think it is a fairly easy problem.
Any info is greatly appreciated.
Thanks,
Darcy

采纳的回答

matt dash
matt dash 2014-12-8
It is unfortunately not a fairly easy problem. The two main problems are: 1) there is no "documented" way to do this, so you won't find it described in the help. 2) presumably you plot everything with a single plot/line object. This can only trigger an event that says "the mouse is over your data". to figure out WHICH data point it's over, you need to do all the calculations yourself.
I have attached a demo file that i made that shows the basics. For real implementations i like to also add a timer to the windowbuttonmotionfcn so it only runs if the mouse has been stationary for e.g. 0.1 seconds... this prevents popups from going all over the place when you're just moving over data. Also this example seems to do a lot of flashing when i run it in 2014b... not sure why that's happening... it's an old example. I certainly still do this kind of thing in 2014b and it works fine with no flashing, so i'm sure there's a workaround.
  1 个评论
matt dash
matt dash 2014-12-8
Edit: i think the flashing is because i delete/recreate the tooltip each time. A better approach would be to check if the tooltip actually needs to change, and if not, do nothing. In older versions deleting and recreating wouldn't flash without explicitly calling drawnow, but it looks like for whatever reason in 2014b you get an animation frame that draws the deletion.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by