필터 지우기
필터 지우기

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

조회 수: 45 (최근 30일)
Darcy
Darcy 2014년 12월 8일
댓글: matt dash 2014년 12월 8일
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