필터 지우기
필터 지우기

determine axes handle to which a legend belongs

조회 수: 12 (최근 30일)
Julian Hapke
Julian Hapke 2016년 4월 4일
댓글: Julian Hapke 2016년 4월 4일
Hi,
pre 2014b I was able to use the following to get the axes handle to which a legend belongs
figure;
plot(sin(0:0.1:3));
l=legend('toggle');
a=get(l,'UserData');
a=a.PlotHandle;
from 2014b on this throws an error, because the UserData is empty.
Is there a way to determine to which axes in an existing figure a legend belongs? As an example:
y = rand(3,5);
figure(11)
s1 = subplot(2,2,1);
bar(s1,y);
l = legend('toggle');
s2 = subplot(2,2,2);
bar(s2,y);
In the example I either want to get l from s1 or s1 from l. s2 is there to make in non-trivial.
Thanks!

채택된 답변

Walter Roberson
Walter Roberson 2016년 4월 4일
I recently noticed that legend and colorbar in R2014a and earlier have a hidden property named Axis . I suspect the property might still be there in R2015a onward; you could try that.
  댓글 수: 1
Julian Hapke
Julian Hapke 2016년 4월 4일
Hi Walter, the "Axes"-Property did exactly what I was looking for, thank you!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by