필터 지우기
필터 지우기

Interpreter doesn't work in legend when legend has multiple outputs (2016b)?

조회 수: 10 (최근 30일)
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?

채택된 답변

Walter Roberson
Walter Roberson 2017년 1월 31일
When you use multiple outputs of legend() in R2014b or later, it constructs the graphics differently, creating line and text objects instead of handling the objects internally. You can extract the text objects out of what it returns and set their Interpreter property.
  댓글 수: 3
Dan Gianotti
Dan Gianotti 2017년 2월 9일
Thanks -- I got it to work the way you suggested: requesting multiple outputs even though the documentation tells me not to do so, then messing with the text objects afterwards.
I'm sure the good folks at Mathworks are probably working on this, but this seems both poorly implemented and poorly documented at present, which is not a great combo. Messing with both text and icons in a legend seems like pretty common usage.
Request for improvement in 2017a?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Star Strider
Star Strider 2017년 1월 31일
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
Dan Gianotti
Dan Gianotti 2017년 2월 9일
Thanks -- ignoring the documentation seems to be the trick here (grumble grumble). I guess it's a testament to Mathwork's documentation that this is the first time I've felt directly misled, but still, it seems like something needs fixing here.
I'll check out your function too!
Vince Badagnani
Vince Badagnani 2017년 4월 3일
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.

댓글을 달려면 로그인하십시오.

카테고리

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