Get plot lines title in a GUI plot by mouse click on each line

4 views (last 30 days)
abaza
abaza on 6 Jan 2022
Commented: abaza on 6 Jan 2022
Hi! I am trying to incorporate a function or button in a GUI via GUIDE, so as to show me the tilte of each plotted line in a plot.
Namely, I am plotting various spectra (i.e. x,y data) and I would like to click on each line and get the title of the spectrum (see attached a picture)!
Could anyone provide me with a hint on how to do this?
Thank you in advance!

Accepted Answer

Jan
Jan on 6 Jan 2022
Edited: Jan on 6 Jan 2022
You can define a ButtonDownFcn for the lines:
LineH(1) = plot(1:10, rand(1, 10), 'r', 'DisplayName', 'Line 1');
LineH(2) = plot(1:10, rand(1, 10), 'b', 'DisplayName', 'Line 2');
TitleH = text(0.01, 0.01, '', 'Units', 'normalized', ...
'VerticalAlignment', 'top');
LineH.ButtonDownFcn = {@showTitle, LineH, TitleH}; % [EDITED] Typo: "," -> "="
function showTitle(aLineH, EventData, LineH, TitleH)
TitleH.String = aLineH.DisplayName;
LineH.LineWidth = 0.5;
aLineH.LineWidth = 1.5;
uistack(aLineH, 'top');
end
  3 Comments

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by