指定した Axes 上に表示されている Legend オブジェクトのハンド​ルを取得することはで​きますか?

조회 수: 7 (최근 30일)
MathWorks Support Team
MathWorks Support Team 2017년 8월 9일
답변: MathWorks Support Team 2017년 8월 9일
subplot 関数を使用して、Figure 上に複数の座標軸(Axes オブジェクト)を作成しています。
それぞれに Axes には、凡例(Legend オブジェクト)を表示していますが、指定した Axes の上にある Legend オブジェクトのハンドルを取得する方法を教えてください。
figure
ax1 = subplot(211);
h11 = plot(1:10,rand(1,10),'DisplayName','A1Data1');
hold on
h12 = plot(1:10,rand(1,10),'DisplayName','A1Data2');
legend('show')
ax2 = subplot(212);
h21 = plot(1:10,rand(1,10),'DisplayName','A2Data1');
hold on
h22 = plot(1:10,rand(1,10),'DisplayName','A2Data2');
legend('show')

채택된 답변

MathWorks Support Team
MathWorks Support Team 2017년 8월 9일
Legend オブジェクトは、Figure の子オブジェクトとして配置されているため、 直接的に Axes から対応する Legend を取得することはできません。 
代替案として、予め、Legend の UserData プロパティに Axes のハンドルを格納する方法が考えられます。 
figure
ax1 = subplot(211);
h11 = plot(1:10,rand(1,10),'DisplayName','A1Data1');
hold on
h12 = plot(1:10,rand(1,10),'DisplayName','A1Data2');
L_h1 = legend('show'); % 凡例表示
L_h1.UserData = ax1; % UserData として Axes ハンドルを登録
% Axes ハンドルから Legend オブジェクトを検出
findobj(gcf,'Type','Legend','UserData',ax1)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!