skip legend entries in dynamiclegend
10 views (last 30 days)
Show older comments
Hi, I wrote a GUI-Programm where you can load a Data-Table and make different plots by clicking one of the buttons. Thode plots are all made in the same axis. The dynamiclegend function allow to update the legend for each plot. There is one loop, in wich plots are created and every one of them has a text labeling it next to it. So these plots shouldnt have any legend entries. Unfortunatly by plotting these (smoothingspline-fits) there is a "data"- and a "fitted curve"-entry in the legend. Ive been googling a lot and reading a lot of matlab-help concearning this matter and just cant figure it out. Hope this works without publishing my code. thanks
0 Comments
Answers (2)
Yair Altman
on 29 Jul 2015
Edited: Yair Altman
on 29 Jul 2015
Specifically:
hasbehavior(hLine, 'legend', false); % line will not be in legend
hasbehavior(hLine, 'legend', true); % line will be in legend
Steven Lord
on 15 Jul 2015
I don't see any function named DYNAMICLEGEND in the documentation. Are you just calling LEGEND (perhaps with the "show" option) each time a new entry is added to the axes?
If so, call LEGEND with a vector of handles of objects you want to appear in the legend. If you have the DisplayName property of those objects set, you can call LEGEND just with the vector of handles.
% Create two plots
h = plot(1:10, 1:10, 'DisplayName', 'line');
hold on
h2 = plot(1:10, (1:10).^2./10, 'DisplayName', 'curve');
% Display just 'line' in the legend
legend(h)
% Display just 'curve' in the legend
legend(h2)
% Display both in the legend
legend([h, h2])
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!