MATLAB Answers

1

Refresh legend from the command line

Asked by Stephan Heise on 19 Jan 2012
Latest activity Answered by Jim Hokanson on 20 Dec 2018
Right-clicking a legend gives the option to "refresh" the legend.
Does anyone know of a way to call "refresh legend" from the command line?

  0 Comments

Sign in to comment.

Tags

Products

4 Answers

Answer by Stephan Heise on 12 Apr 2012
 Accepted Answer

In the meantime I found an answer elsewhere:
It is possible to access any context menu item via the axes' UIContextMenu property. For details see http://undocumentedmatlab.com/blog/legend-semi-documented-feature/#comment-70611.
Stephan.

  0 Comments

Sign in to comment.


Answer by Junaid
on 19 Jan 2012

Dear,
legend('-DynamicLegend');
it will refresh. And update the contents dynamically, either you delete something from plot or you add something:-)
I hope this is what you are required..:-)

  0 Comments

Sign in to comment.


Answer by Stephan Heise on 19 Jan 2012

Hi Junaid,
thanks for the fast reply! I recently stumbled upen the "DynamicLegend" option myself and first thought, this was the same as the context-menu's "refresh". However, ‘DynamicLegend’ only seems to react to additions or deletions to the axes: switching the ‘Visibility’ of a line to ‘off’ or switching the legend entry off by
set(get(get(line_handle,'Annotation'),'LegendInformation'),'IconDisplayStyle','off')
is ignored by the ‘DynamicLegend’ feature. :( The “refresh” function correctly removes the corresponding legend entry in these cases.

  0 Comments

Sign in to comment.


Answer by Jim Hokanson on 20 Dec 2018

I've found hiding and showing the legend works.
ax = gca; %might be different ...
legend(ax,'hide');
legend(ax,'show');

  0 Comments

Sign in to comment.