将两个Matlab图形彼此相邻绘制

时间:2016-01-13 15:35:20

标签: matlab figure subplot

我试图将这两个数字绘制在一起。我们的想法是在x轴上创建1到10的正方形图。我知道subplot功能,但有些它不适合我。非常感谢帮助。

   % plotting the data
data1_plot=data1.*100; 
data2_plot=data2.*100; 
figure(1),
subplot(1,2,1); 
plot((1:10)',mean(data1_plot),'o-','LineWidth',1);hold on
for ii=2:10;
    if mean(data1_plot(:,ii))<mean(data1_plot(:,ii-1));
        plot([ii-1,ii],mean(data1_plot(:,ii-1:ii)),'r.-');
    end
end
set(gca,'XTickLabel',{'Unprofitable';'2';'3';'4';'5';'6';'7';'8';'9';'Profitable'});
axis([0.8,10.2,0.0,1.5]),...
    ylabel('Average return'),...
    title('\rm Equally-weighted PMU portfolio returns, 1990-2015');hold off;
subplot(1,2,2); 
plot((1:10)',mean(data2_plot),'o-','LineWidth',1);hold on
for ii=2:10;
    if mean(data2_plot(:,ii))<mean(data2_plot(:,ii-1));
        plot([ii-1,ii],mean(data2_plot(:,ii-1:ii)),'r.-');
    end
end
set(gca,'XTickLabel',{'Weak';'2';'3';'4';'5';'6';'7';'8';'9';'Robust'});
axis([0.8,10.2,0.0,1.5]),...
    ylabel('Average return'),...
    title('\rm Equally-weighted RMW returns, 1990-2015');hold off;

plots

1 个答案:

答案 0 :(得分:3)

您可以使用

axis square
xlim([1 10])

第一个命令使当前轴区域为方形(web),第二个命令设置x轴限制。

示例:

subplot(1,2,1)
plot(1:10);
axis square
xlim([0 12]);

subplot(1,2,2)
plot(1:10);
axis square
xlim([1 10]);

enter image description here

相关问题