tooltip on multiple axes contained on a panel

5 ビュー (過去 30 日間)
marco
marco 2011 年 6 月 7 日
回答済み: Anay 2025 年 3 月 7 日
hello, I got a panel in a certain part of a figure, with as many axes as I want. I want to visualize the number of the plot when i pass over the axes with the mouse. How can I manage it? Any idea? I was looking for a solution with tooltipstring (but it doesn't exist for axes), i was also trying with WindowButtonMotionFcn, but axes are on a panel, so I can't use that. thank you, marco

回答 (1 件)

Anay
Anay 2025 年 3 月 7 日
Hi Marco,
I understand that you have a figure which contains a panel with many axes and you want to display the axis on which the mouse pointer hovers.
Your approach of using the “WindowButtonMotionFcn” callback of the figure seems correct. Inside the “WindowButtonMotionFcn” callback,
  1. Iterate over all the axes in your panel.
  2. For each axis, use “getpixelposition function with isrecursive argument passed as true to get position of the axis relative to the parent figure.
  3. Check if the current position of the mouse is within the location of that axis.
  4. If yes, display the axis name/number on the parent figure’s title
You can refer to the below code for example:
% Inside the logic that goes into the "WindowButtonMotionFcn"
% Check which axes the mouse is over
for i = 1:length(axArray)
axPos = getpixelposition(axArray(i), true);
if isInAxes(currentPoint, axPos)
tooltipText = sprintf('Plot %d', i);
break;
end
end
You can use the "Name" property of the parent figure to display the plot name as title of the figure.
fig.Name = ['Figure Title Text - ' tooltipText];
For more information you can consider checking out the documentation of the “getpixelposition” function by using the following command in your MATLAB command window:
>>doc getpixelposition
I hope this addresses the issue!

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by