skip legend entries in dynamiclegend

10 views (last 30 days)
Shurrik
Shurrik on 15 Jul 2015
Commented: Shurrik on 27 Nov 2015
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

Answers (2)

Yair Altman
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
  2 Comments
Shurrik
Shurrik on 27 Nov 2015
thanks you! Now the "data"-entry is hidden, but it still shows the "fitted curve"-entry. Here's my code, wich is located under a function for pushbutton_callback.
Shurrik
Shurrik on 27 Nov 2015
ok the solution is
DK_Smooth=fit(n_DK,M_DK,'Smoothingspline','SmoothingParam',1)
h(d,:)=plot(DK_Smooth,n_DK,M_DK)
hasbehavior(h(d), 'legend', false);
hasbehavior(h(d,2), 'legend', false);
cheers :)

Sign in to comment.


Steven Lord
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])
  1 Comment
Shurrik
Shurrik on 15 Jul 2015
hmm that wont work or will be complicated because every one of the plot is created in a different callback-function (function pushbutton3-callback....4...5...6). Wich means I cant access the plots globally just like that to control the legend feature for each of them,right?. Anywy the dynamiclegend seems to be a rarely nown feature http://undocumentedmatlab.com/blog/legend-semi-documented-feature

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!