How to update legend in MatLab R2017a

6 次查看(过去 30 天)
I found that in the new version of MatLab, R2017a, they removed the option of updating the legend (Right-Click on legend ----> select the option Refresh). So, how one can update the legend in MatLab R2017a?
  1 个评论
Romilde Kotze
Romilde Kotze 2017-8-23
I have the same problem when I hide some curves. How did you manage to get the legend to refresh because it's definitely not updating automatically?

请先登录,再进行评论。

回答(2 个)

Walter Roberson
Walter Roberson 2017-3-19
In r2017a, legends should update automatically. It is one of the graphics changes in the release
  4 个评论
Romilde Kotze
Romilde Kotze 2017-8-23
Unfortunately, that doesn't solve the problem. The auto update isn't working properly
Walter Roberson
Walter Roberson 2017-8-23
If you used the old style legend() call with multiple outputs, then legend objects are built differently and will not automatically update.
For the new-style legend() call, the legend AutoUpdate property controls automatic updating. The default is now true, but that might be overridden by a figure or root DefaultLegendAutoUpdate property.
To hide particular items, you can set their HandleVisibility off, or set their annotation IconDisplayStyle off.
According to Mathworks at https://www.mathworks.com/matlabcentral/answers/353013-in-2017a-how-do-i-prevent-a-legend-item-from-being-greyed-out-when-the-plot-line-is-set-with-visi#answer_278712 the behavior of graying legend entries for items whose visibility is off cannot be generally overridden.

请先登录,再进行评论。


Mario Buchely
Mario Buchely 2018-3-30
Hi, I had same problem with Matlab 2017a. It seems new version uses new features that does not allow to do the 'refresh' in legend using the figure GUI. After trying different things, I just did a simple procedure: delete the non-useful plots. If you need to keep the plots, and if you don't want to mess with code, I recommend to do: 1. Deactivate the AutoUpDate property using the following command: >>menuset(groot,'defaultLegendAutoUpdate','off') 2. Open your figure in the GUI and edit all plots as you finally want to show (names, types, colors, etc.) 3. Save as figure at this point if you need to reset something 4. Select plots you don't want to show in legend 5. Delete those plots 6. Insert legend 7. Undo: Delete (Ctl+z) 8. Edit legend title and move it to the desired position 9. Save as or copy your new figure with the right legend.
Now, you should be able to show your figure using just the desire name for plots in legend. If you just miss some step, just close the figure and open the save version in the step 3. Finally, if you want to activate the AutoUpDate property of legend again, just type: >>menuset(groot,'defaultLegendAutoUpdate','on')

类别

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