Matlab 如何为子地块创建通用图例?
我正在尝试创建一个子地块的图形。我不希望子地块有图例,而是希望图形有一个整体图例 我了解到,通过Matlab 如何为子地块创建通用图例?,matlab,matlab-figure,legend,figure,subplot,Matlab,Matlab Figure,Legend,Figure,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}); tit
图例
的位置
功能,或者使用一个子地块图形位置(例如子地块(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
代码:
% 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
输出:
% 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
我的收获是,你可以在子批次中增加
0.5
,我不知道!巧妙的解决方案。我想补充一点,subplot()
的第一个参数必须是整数,但其他参数显然不必是整数!