Matlab双轴设置

clc;clear;
z=0:2.5:3000;
[syncl_cp,~,~]=ReadSu('syncl_cp.su');
[syncl_ro,~,~]=ReadSu('syncl_ro.su');
cp = syncl_cp(:,1);
ro = syncl_ro(:,1);
% plot(z,cp)
plot(z,cp,'b','LineWidth',1.5)
hold on;
plot(z,ro,'r--','LineWidth',1.5)
axis([0 3000 500 3000]); % 设置坐标轴在指定的区间
xlabel('深度(m)')
ylabel('声速(m/s)')

[AX,H1,H2] = plotyy(z,cp,z,ro,'plot');
set(AX(1),'XColor','k','YColor','b');
set(AX(2),'XColor','k','YColor','r');
%设置左轴
HH1=get(AX(1),'Ylabel');
set(HH1,'String','声速(m/s)');
set(HH1,'color','b');
% set(AX(1),'ylim',[500,3000]);
%设置右轴
HH2=get(AX(2),'Ylabel');
set(HH2,'String','密度(kg/m^3)');
set(HH2,'color','r');
% set(AX(2),'ylim',[500,3000])

set(H1,'LineStyle','-','LineWidth',1.5);
set(H1,'color','b');
set(H2,'LineStyle',':','LineWidth',1.5);
set(H2,'color','r');
legend([H1,H2],{'声速(m/s)';'密度(kg/m^3)'});
% axis([0 3000 500 3000]); % 设置坐标轴在指定的区间
xlabel('深度(m)');
% title('Labeling plotyy');
View Code

 

posted @ 2018-07-03 10:31  阳光正好只欠拥抱  阅读(305)  评论(0编辑  收藏  举报