The transparency of patch in legend changes when the legend is updated in the plot browser in the figure. How can I stop it?

4 views (last 30 days)
Why does the patch transparency of a filled plot change when I update the legend in the plot browser?
I would like to plot my curves and then hide/delete some of them and then update the figure and legend using the features in the plot browser. Unfortunately,the patch transparency for my one curve changes if I refresh or delete and reinsert the legend. Also, I notice the text (latex) for the one curve doesn't come out properly unless I reinsert the legend directly in the plot browser. Why? ( I need some of the text in 'latex' and others in 'tex')
I also don't understand why I get this error 'Error using matlab.graphics.primitive.Data/set...There is no interpreter property on the Line class.'
Here's a sample of my code (note my actual script has a lot more line curves and a at least 2 filled curves). I am using Matlab 2016b.
Thanks

Accepted Answer

Elizabeth Reese
Elizabeth Reese on 4 Dec 2017
Any time the legend creates new patches, they will default to the non-transparent FaceAlpha. Using the syntax to return the LegIcon set is not recommended in the documentation as it does not support all graphics features and may not automatically update as you add or remove data series from the axes. To address this, MathWorks is working on an update to the legend so that the patches in the legend are the same FaceAlpha as their corresponding lines. This update is being considered for a future release of MATLAB.
As to the error you are seeing, that is because LegIcon includes the line, text, and patch objects that are children of the legend. The set command is trying to set the interpreter for each of these objects, but Line objects do not have this property. Try changing this set command to:
set(findobj(LegIcon,'type','text'),'interpreter', 'latex', 'fontsize', 8);
  1 Comment
Romilde Kotze
Romilde Kotze on 5 Dec 2017
Thanks so much that solved the error problem. Do you know if there is a work around to get the patches to update? or at least be able to set the default alpha for patches in the legend?

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!