Display information about a point by hovering over it on a figure
60 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
matt dash
il 8 Dic 2014
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 Commento
matt dash
il 8 Dic 2014
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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Specifying Target for Graphics Output in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!