Refresh legend from the command line

28 vues (au cours des 30 derniers jours)
Stephan Heise
Stephan Heise le 19 Jan 2012
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?

Réponse acceptée

Stephan Heise
Stephan Heise le 12 Avr 2012
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

Plus de réponses (3)

Junaid le 19 Jan 2012
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 le 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
is ignored by the ‘DynamicLegend’ feature. :( The “refresh” function correctly removes the corresponding legend entry in these cases.

Jim Hokanson
Jim Hokanson le 20 Déc 2018
I've found hiding and showing the legend works.
ax = gca; %might be different ...



Community Treasure Hunt

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

Start Hunting!

Translated by