天天看点

【分享】Matlab绘制双Y轴曲线

可直接复制运行,根据需要修改!

%绘图数据
x=0:0.1:20;
y1=sin(x);
y2=cos(x);
% 绘图
[hAx,hLine1,hLine2] =plotyy(x',y1,x',y2);
%设置图幅
xlim( hAx( 1 ), [1 10] );
xlim( hAx( 2 ), [1 10]);
%设置线型
hLine1.LineStyle = '-';
hLine2.LineStyle = '--';
%设置线宽
hLine1.LineWidth=1.0;
hLine2.LineWidth=1.0;
%设置标记
hLine1.Marker='o';
hLine2.Marker='^';
%设置图例
legend('Y1','Y2','Location','northeast','Fontsize',16,'Fontname','宋体','FontWeight','bold','linewidth',0.6)
% 设置字体(应该先设置全局字体为Times New Roman,然后设置宋体这些,否则宋体显示不全)
set(gcf,'color','w');
set(hAx(1),'Fontsize',16,'linewidth',1.0);
set(hAx(2),'Fontsize',16,'linewidth',1.0);
% set(gca,'Fontsize',16,'Fontname','Times New Roman','FontWeight','normal','linewidth',1.6);
xlabel('时间/s','Fontsize',16,'Fontname','宋体','FontWeight','bold');
ylabel(hAx(1),'Y1/℃','Fontsize',16,'Fontname','宋体','FontWeight','bold') ;
ylabel(hAx(2),'Y2/cm','Fontsize',16,'Fontname','宋体','FontWeight','bold');
           
【分享】Matlab绘制双Y轴曲线

继续阅读