subplot绘制子图会自动分配子图范围避免子图重叠,我们绘制共用x轴图时需要若干图的x轴重叠,会出现子图不显示的问题,这是由于subplot判定子图重叠,然后被后续子图覆盖了,解决办法是先画子图再调整子图位置。下面是我复现一篇论文的例子,四个图共用一个x轴:
clc;close;
h1=subplot(4,1,1);
plot(t,H,'*')
hold on
plot(t,H)
set(gca,'xticklabel',[],'YLim',[30 90]);
ylabel('H km')
h2=subplot(4,1,2);
plot(t,v,'o')
hold on
plot(t,v)
set(gca,'xticklabel',[],'YLim',[2000 7000]);
ylabel('V m/s')
set(gca,'yaxislocation','right')
h3=subplot(4,1,3);
plot(t,gamma,'o')
hold on
plot(t,gamma)
set(gca,'xticklabel',[],'YLim',[-5 5]);
ylabel('γ deg')
h4=subplot(4,1,4);
plot(t,theta,'o')
hold on
plot(t,theta)
set(gca,'xticklabel',[],'YLim',[0 120]);
xlabel('Time sec')
ylabel('Longitude deg')
set(gca,'yaxislocation','right')
% 设置子图位置
set(h1,'position',[0.2 0.65-0.005 0.6 0.15])
set(h2,'position',[0.2 0.50-0.005 0.6 0.15])
set(h3,'position',[0.2 0.35-0.005 0.6 0.15])
set(h4,'position',[0.2 0.2-0.005 0.6 0.15])
set(gca,'color',[1 1 1])