Clear Filters
Clear Filters

How to update legend in MatLab R2017a

4 views (last 30 days)
Jamal Ahmad
Jamal Ahmad on 19 Mar 2017
Answered: Mario Buchely on 30 Mar 2018
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 Comment
Romilde Kotze
Romilde Kotze on 23 Aug 2017
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?

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 19 Mar 2017
In r2017a, legends should update automatically. It is one of the graphics changes in the release
  4 Comments
Romilde Kotze
Romilde Kotze on 23 Aug 2017
Unfortunately, that doesn't solve the problem. The auto update isn't working properly
Walter Roberson
Walter Roberson on 23 Aug 2017
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.

Sign in to comment.


Mario Buchely
Mario Buchely on 30 Mar 2018
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')

Tags

Products

Community Treasure Hunt

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

Start Hunting!