필터 지우기
필터 지우기

Extract "labelhandles" from Legend

조회 수: 3 (최근 30일)
Sim
Sim 2023년 6월 1일
편집: Sim 2023년 6월 2일
Given the definition of Legend in Matlab:
[leg,labelhandles,outH,outM] = legend(varargin)
Would it be possible to get the content of the second output of the legend, i.e. "labelhandles", just by calling the first output of the legend, i.e.
leg = legend(varargin)
?
  댓글 수: 3
Adam Danz
Adam Danz 2023년 6월 1일
@Sim, before you get too far down that route, know that the additional outputs to legend used to be documented but are no longer documented nor fully supported. Using the undocumented additional legend handles have lead to unexpected behaviors. For example, unexpected fontsize and fontweight, (here too).
Even if you manage to get the legend object handles and adjust their properties, those adjustments may not sustain after saving/loading the figure or when the figure is in Live editor.
I'm not saying you'll definitiely run into these problems, but you might.
Sim
Sim 2023년 6월 2일
편집: Sim 2023년 6월 2일
Thanks a lot both @Cris LaPierre and @Adam Danz for your comments!
@Adam Danz, good to know! :-) OK, I will not take that route then... However, I would say that the problem to get access to objects that are typically shown/extracted thorugh the second output, i.e. "labelhandles", still remain unsolved... at least to the best of my understanding..... Unless, on File Exchange, there are alternative functions to get the same legend's properties and objects, or, @MathWorks Support Team has a new version of the legend's function in the pipeline.... :-)

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

채택된 답변

Matt J
Matt J 2023년 6월 1일
편집: Matt J 2023년 6월 1일
Would it be possible to get the content of the second output of the legend, i.e. "labelhandles", just by calling the first output of the legend
I was told very recently by Tech Support that it is not possible:
On Wed, Mar 15, 2023 at 9:45AM Laura Li <support@mathworks.com> wrote:
Hello Matt,
Unfortunately there is not. You'd have to use the workaround mentioned previously if you want to have two handles and the properties set correctly. Compatible legend is maintained to prevent old workflows from breaking but new features are not supported for this legend.
On the other hand, could you provide more information on your entire workflow? As in what is your goal with getting the handles to each patch objects? We'd like to support the workflow one day, and we want to make sure your use case is considered in future enhancement plans.
Sincerely,
Laura Li
MathWorks Technical Support
--------------- Original Message ---------------
From:
Sent: 3/14/2023, 4:29 PM
Subject: Re: legend() ignores FaceAlpha [ ref:_00Di0Ha1u._5003q1aAxgK:ref ]
I'm talking about obtaining handles to the patches inside the legend box, such as the handle PatchInLegend handle from your previous code example, ...So my question is really, is there a supported way to obtain PatchInLegend without relying on the two-output syntax of legend() as you did earlier?
  댓글 수: 1
Sim
Sim 2023년 6월 2일
편집: Sim 2023년 6월 2일
@Matt J Thanks a lot! I have the same issue, i.e. "obtaining handles to the patches inside the legend box"..... Is your email to @MathWorks Support Team related to some public thread here on Matlab Answer that I could take a peek at? (no problem if it is only a private exchange of emails)

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

추가 답변 (0개)

카테고리

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