Refresh legend from the command line

조회 수: 20 (최근 30일)
Stephan Heise
Stephan Heise 2012년 1월 19일
답변: Jim Hokanson 2018년 12월 20일
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?

채택된 답변

Stephan Heise
Stephan Heise 2012년 4월 12일
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.

추가 답변 (3개)

Junaid
Junaid 2012년 1월 19일
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..:-)

Stephan Heise
Stephan Heise 2012년 1월 19일
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.

Jim Hokanson
Jim Hokanson 2018년 12월 20일
I've found hiding and showing the legend works.
ax = gca; %might be different ...
legend(ax,'hide');
legend(ax,'show');

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by