Interpreter doesn't work in legend when legend has multiple outputs (2016b)?
Show older comments
Hi, I think I may have found a weird bug in 2016b. The following works as expected:
p = plot(1:2,2:3);
l = legend({'My Line'},'Interpreter','latex');
But if I request an additional output the interpreter stops working:
p = plot(1:2,2:3);
[l,a] = legend({'My Line'},'Interpreter','latex');
This is even true if instead you write:
[l,~] = legend({'My Line'},'Interpreter','latex');
This isn't just me, right?
Accepted Answer
More Answers (1)
Star Strider
on 31 Jan 2017
1 vote
From the documentation:
- [lgd,icons,plots,txt] = legend(_) additionally returns the objects used to create the legend icons, the objects plotted in the graph, and an array of the label text. Note: This syntax is not recommended. It creates a legend that does not support all graphics features. Instead, use the lgd = legend() syntax to return the legend object and set Legend Properties. (Emphasis mine)
4 Comments
Dan Gianotti
on 2 Feb 2017
Kelly Kearney
on 2 Feb 2017
Even though the docs try to steer you away from the old syntax, it will still work for most purposes. And for more complicated instances where regular legend refuses to play nicely, try my legendflex.m function; I've added workarounds for most of those problems (like the text interpreter one mentioned in the original question).
Dan Gianotti
on 9 Feb 2017
Vince Badagnani
on 3 Apr 2017
Yes, I'm running into this as well. My code worked in R2015b as follows:
[FFT_legend, ObjH, ~, ~] = legend(ltext, 'Location', 'best', 'Interpreter', 'none');
FFT_legend.FontSize = 20;
The variable ltext is a Mx1 cell array. But now I'm finding in R2016b that I have to write my code as follows:
[FFT_legend, ObjH, ~, ~] = legend(ltext);
txt = findobj(ObjH, 'Type', 'Text');
arrayfun(@(x) set(x, 'FontSize', 20, 'Interpreter', 'none'), txt);
FFT_legend.Location = 'best';
But it gives me a warning when attempting to set the FFT_legend location.
Warning: Error updating Legend.
Struct contents reference from a non-struct array object.
Categories
Find more on Legend in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!