2017-01-03 15 views
2

私はサブプロットの図を作成しようとしています。私はサブプロットに伝説があるのではなく、全体的な伝説を持つ人物を望んでいます。サブプロットの共通の凡例を取得するにはどうすればよいですか?

私はそれが最後のサブプロットに凡例を追加しlegendposition機能を介して、または(例えばsubplot(2,3,5.5)のみ凡例を表示する)を一度サブプロット図の位置を用いて、図にその位置を調整することによってのいずれかで可能であることを読み取ります。私は今まで成功していませんが、私は第二の選択肢を好むでしょう。どんな助け?ここで

は私のコードです:

SLS=figure(); 
hold on 
subplot(3,2,1); 
plot(t,u{1},t,u{2},t,u{3},t,u{4},t,u{5},t,u{6}); 
title('SLS Levels'); 
subplot(3,2,2); 
plot(t,log_u{1},t,log_u{2},t,log_u{3},t,log_u{4},t,log_u{5},t,log_u{6}); 
title('SLS Logarithms'); 
subplot(3,2,3); 
plot(t,I_u{1},t,I_u{2},t,I_u{3},t,I_u{4},t,I_u{5},t,I_u{6}); 
title('SLS Levels with Intercept'); 
subplot(3,2,4); 
plot(t,log_I_u{1},t,log_I_u{2},t,log_I_u{3},t,log_I_u{4},t,log_I_u{5},t,log_I_u{6}); 
title('SLS Log. with Intercept'); 
subplot(3,2,5.5); 
legend('GDP', 'C', 'I', 'G', 'Imp.', 'Exp.'); 
axis off 
+1

あなたはサルダールのansweを受け入れた場合、それはいいだろうrなので、この質問は完全です。 upvotesとまともな解決策を示すイメージを考えれば、それは良い修正のようだ。そう思っている場合は、緑色の矢印を投票ボタンでクリックしてください。 – Wolfie

答えて

14

コード:

% Plotting some random data and storing their handles 
subplot(3,2,1);  h1 = plot(randperm(10),randperm(10),'ko-'); 
subplot(3,2,2);  h2 = plot(randperm(10),randperm(10),'g+-'); 
subplot(3,2,3);  h3 = plot(randperm(10),randperm(10),'md-'); 
subplot(3,2,4);  h4 = plot(randperm(10),randperm(10),'rv-.'); 

hL = subplot(3,2,5.5); 
poshL = get(hL,'position');  % Getting its position 

lgd = legend(hL,[h1;h2;h3;h4],'RandomPlot1','RandomPlot2','RandomPlot3','RandomPlot4'); 
set(lgd,'position',poshL);  % Adjusting legend's position 
axis(hL,'off');     % Turning its axis off 

出力:

enter image description here

+0

私はこのことから、サブプロットで「0.5」増分を持つことができることを知っています。きちんとした解決策。 – Wolfie

+0

@Wolfieありがとうございます。 Btwは単に「0.5」に限定されるものではありません。あなたは[1 2]のような範囲を与えることができます。 [この質問](https://stackoverflow.com/questions/37465980/plotting-using-subplot-with-different-x-axis-for-each-plot)を参照してください。また、[1 3.65] 'も使用できます。複数の列にまたがるいくつかのより奇妙な組み合わせも可能です。 –

関連する問題