refreshing legend when Visible is set on/off
3 views (last 30 days)
Show older comments
hello
I would like to know if there is a way to refresh automatically a legend when the visibility of a line is set on/off.
I have several lines plotted and I switch their visibilities using the command:
set(handle,'Visible','on')
% or set(handle,'Visible','off')
which doesn't seem to be taken into account by the ''-DynamicLegend' function.
However right-clicking on the refresh function works correctly
Thank you for your answer
Ewen.
5 Comments
Oleg Komarov
on 6 Apr 2012
I tried to dwell in C:\Program Files\MATLAB\R2012a\toolbox\matlab\scribe\@scribe\@legend\init.m, but have not got very far.
You should ask Technical Support.
Answers (2)
Yair Altman
on 7 Jan 2013
I explained how to do this here: http://undocumentedmatlab.com/blog/legend-semi-documented-feature/#comment-70611
Here is the gist of it:
hLegend = findall(gcf,'tag','legend');
uic = get(hLegend,'UIContextMenu');
uimenu_refresh = findall(uic,'Label','Refresh');
callback = get(uimenu_refresh,'Callback');
hgfeval(callback,[],[]);
0 Comments
Image Analyst
on 6 Apr 2012
I did not observe anything unusual with your code. It plotted the red, green, and blue lines and added the legend immediately after plotting, and then when you deleted the red line, the red legend automatically vanished. This is in R2011b. What version are you running? Maybe it was a bug that got fixed.
One thing you might try is to add a "drawnow" after your calls to plot() to force an update/refresh of the figure.
3 Comments
Image Analyst
on 6 Apr 2012
Oh, you're right. I just blindly ran the script he gave and didn't notice that he didn't have the line of code in there that demonstrated what he wanted to demonstrate.
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!