How to show legend as subfigure

Dear All,
Let say I have subplots of 4 figures. First three figures have some curve plots. I want to show last figure (the forthone) as legend of figure three.
subplot(1,4,1), plot([1:100],'DisplayName','Fig 1');
subplot(1,4,2), plot([1:100],'DisplayName','Fig 2');
subplot(1,4,3), plot([1:100],'DisplayName','Fig 3');
now at figure 4 I want to show legend of figure 3. Is it possible ?

 채택된 답변

Robert Cumming
Robert Cumming 2012년 1월 10일

3 개 추천

With some manipulation of the legend position handle you can:
EDIT: to update the text in legend
subplot(1,4,1), plot([1:100],'DisplayName','Fig 1');
subplot(1,4,2), plot([1:100],'DisplayName','Fig 2');
subplot(1,4,3), fig3handle = plot([1:100],'DisplayName','Fig 3');
a3pos = get ( gca, 'position' )
a = legend ( fig3handle )
get ( a, 'position' )
set ( a, 'position', [(a3pos(1)+a3pos(3)+(1-(a3pos(1)+a3pos(3)))/2)-a3pos(3)/2 a3pos(2) a3pos(3) a3pos(4)] )

댓글 수: 4

Aravin
Aravin 2012년 1월 10일
Dear Robert, Thanks for your reply. But I m interested to get legend of figure 3. Let say in figure 3 I have five strings. So I want to get all in figure 4 position. As your example is pretty good but you are having fix legend('A'); that i don't want.
Please suggest.
Robert Cumming
Robert Cumming 2012년 1월 10일
see updated code.
Basically you pass the plot handle to the legend command.
SUDIP PODDAR
SUDIP PODDAR 2012년 2월 19일
is it possible to add display name dynamically? First time it shows fig 1 & then fig 2 like
c=1:10
subplot(1,4,1), plot([1:100],'DisplayName','Fig 'c);
plz help me
Robert Cumming
Robert Cumming 2012년 2월 23일
subplot(1,4,1), plot([1:100],'DisplayName',sprintf ( 'Fig %i', c ));

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

추가 답변 (0개)

카테고리

Community Treasure Hunt

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

Start Hunting!

Translated by