refreshing legend when Visible is set on/off
Afficher commentaires plus anciens
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 commentaires
Oleg Komarov
le 5 Avr 2012
What is the DynamicLegend function?
Ewen
le 6 Avr 2012
Oleg Komarov
le 6 Avr 2012
I don't see such option in the documentation.
Ewen
le 6 Avr 2012
Oleg Komarov
le 6 Avr 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.
Réponses (2)
Yair Altman
le 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,[],[]);
Image Analyst
le 6 Avr 2012
0 votes
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 commentaires
Oleg Komarov
le 6 Avr 2012
The legend doesn't "update" when you set the line to 'Visible','Off'.
It would be nice to leave the string entry in the legend but make the line invisible or erase the entry from the legend completely.
Image Analyst
le 6 Avr 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.
Ewen
le 10 Avr 2012
Catégories
En savoir plus sur Legend dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!