matlab画双坐标图的样式
%%
clc,clear,close all;
t=0:0.1:9*pi;
figure; [AX,Ha,Hb]=plotyy(t,sin(t),t,exp(t)); % 绘图并创建句柄
% ----------------- 设置刻度
set(AX(1),'yTick',[-1.250:0.25:1.25]) % 设置左边Y轴的刻度
set(AX(2),'yTick',[0:50:350]) % 设置右边Y轴的刻度
% ----------------- 添加标注
d1=get(AX(1),'ylabel'); set(d1,'string','正弦函数');
d2=get(AX(2),'ylabel'); set(d2,'string','指数函数','fontsize',18);
% ----------------- 设置两个Y轴的颜色
%set(ax(:),'Ycolor','k') % 设定两个Y轴的颜色为黑色
% ----------------- 设置线型
set(Ha,'linestyle','-','marker','o','color','r','linewidth',2);
set(Hb,'linestyle','-','marker','*','color','b','linewidth',2);
% ----------------- 添加图例
hold on;
Hc=line(t,(sin(t)+cos(t))/2); % 绘图并创建图形句柄
set(Hc,'linestyle','-','marker','s','color','m');
legend([Ha,Hb,Hc],'sin(t)','exp(t)','(sin(t)+cos(t))/2'); % 加注图例
set(gcf,'Position',[50 50 1200 1200],'Color','w')
export_fig('1.png','-r300');
%%
clc,clear,close all;
x=0:0.01:10;
y1=sin(x);
y2=10*cos(x);
y3=0.5*sin(x);
[AX,H1,H2]=plotyy(x,[y1;y3],x,y2,'plot');%双轴
set(AX(1),'XColor','k','YColor','M','linewidth',2); %X轴和第一个Y轴的颜色
set(AX(2),'XColor','k','YColor','r','linewidth',2); %X轴和第二个Y轴的颜色
HH1=get(AX(1),'Ylabel');
set(HH1,'String','sin','color','M'); %第一个Y轴标签的的颜色
HH2=get(AX(2),'Ylabel');
set(HH2,'String','cos','color','r'); %第二个Y轴标签的的颜色
set(AX(1),'ylim',[-1,1],'ytick',[-1,-0.5,0,0.5,1]); %定第一个Y轴的范围
set(AX(2),'ylim',[-10,10],'ytick',[-10,-5,0,5,10]); %定第二个Y轴的范围
set(H1(1),'LineStyle','-','linewidth',1.5,'color','M','linewidth',2); %y1的线型设置
set(H1(2),'LineStyle','--','linewidth',1.5,'color','g','linewidth',2);%y3的线型设置
set(H2,'LineStyle','-','linewidth',1.5,'color','r'); %y2的线型设置
legend([H1(1),H1(2),H2],{'y1';'y3';'y2'});
xlabel('x');
set(gcf,'Position',[50 50 1200 1200],'Color','w')
export_fig('2.png','-r300');
%%
clc,clear,close all;
x=1:0.1:100;
y1=x;
y2=x.^3;
plotyy(x,y1,x,y2,@plot,@semilogy)
export_fig('30.png','-r300');
%%
clc,clear,close all
x=linspace(0,10);%构建行向量,第一个元素是0,最后一个元素是10,共默认为100个元素的等差数列
y1=200*exp(-0.05*x).*sin(x);%exp以e为底的指数函数,.*矩阵的对应元素相乘
y2=0.8*exp(-0.5*x).*sin(10*x);
y3=0.2*exp(-0.5*x).*sin(10*x);
[hAx,hLine1,hLine2]=plotyy(x,y1,[x',x'],[y2',y3']);%"'"表示转置矩阵,matlab中矩阵是按列存储
set(gcf,'Position',[50 50 1200 1200],'Color','w')
export_fig('3.png','-r300');
%%
clc,clear,close all
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
figure; [AX,H1,H2] = plotyy(x,y1,x,y2,'plot');
% ----------------- 设置坐标轴的颜色
set(AX(1),'XColor','k','YColor','b','linewidth',2);
set(AX(2),'XColor','k','YColor','r','linewidth',2);
% ----------------- 添加Y轴标注
HH1=get(AX(1),'Ylabel');
set(HH1,'String','Left Y-axis','color','b','linewidth',2);
HH2=get(AX(2),'Ylabel');
set(HH2,'String','Right Y-axis','color','r','linewidth',2);
% ----------------- 图形设置
set(H1,'LineStyle','-','color','b','linewidth',2);
set(H2,'LineStyle',':','color','r','linewidth',2);
% ----------------- 添加图例、X轴标注、标题
legend([H1,H2],{'y1 = 200*exp(-0.05*x).*sin(x)';'y2 = 0.8*exp(-0.5*x).*sin(10*x)'});
xlabel('Zero to 20 musec.','FontSize',14); title('Labeling plotyy','FontSize',14);
set(gcf,'Position',[50 50 1200 1200],'Color','w')
export_fig('4.png','-r300');
%%
clc,clear,close all;
%clf reset; % 从当前图窗中删除所有图形对象
tp=(0:100)/100*5;yp=8+4*(1-exp(-0.8*tp).*cos(3*tp)); % 压力数据
tt=(0:500)/500*40;yt=120+40*(1-exp(-0.05*tt).*cos(tt)); % 温度数据
% ----------------- 创建笛卡尔(直角)坐标系一
h_ap=axes('Position',[0.13,0.13,0.7,0.75]); %<4>
% ----------------- 设置坐标轴颜色、范围、间隔,开启网格
set(h_ap,'Xcolor','b','Ycolor','b','Xlim',[0,5],'Ylim',[0,15],'linewidth',2);
nx=10;ny=6; %<6>
pxtick=0:((5-0)/nx):5;pytick=0:((15-0)/ny):15; %<7>
set(h_ap,'Xtick',pxtick,'Ytick',pytick,'Xgrid','on','Ygrid','on','FontSize',14,'linewidth',2)
set(get(h_ap,'Xlabel'),'String',' 时间 \rightarrow (分) ','FontSize',14)
set(get(h_ap,'Ylabel'),'String',' 压力 \rightarrow(\times 10^{5} Pa )','FontSize',14)
% ----------------- 添加图形
line(tp,yp,'Color','b','linewidth',2); %<9>
% ----------------- 创建坐标系二
h_at=axes('Position',get(h_ap,'Position')); %<12>
% ----------------- 设置坐标轴颜色、范围
set(h_at,'Color','none','Xcolor','r','Ycolor','r','linewidth',2); %<13>
set(h_at,'Xaxislocation','top') %<14>
set(h_at,'Yaxislocation','right','Ydir','rev') %<15>降序
set(h_at,'Ylim',[0,210]) %<18>
set(get(h_at,'Xlabel'),'String','\fontsize{15}\fontname{隶书} 时间 \rightarrow (分) ')
set(get(h_at,'Ylabel'),'String',' ({\circ}C )\fontsize{15}\leftarrow\fontname{隶书} 零下温度 ')
% ----------------- 添加图形
line(tt,yt,'Color','r','Parent',h_at,'linewidth',2) %<19>
% ----------------- 设置坐标间隔
xpm=get(h_at,'Xlim'); %<20>添加图形后才能得到Xlim
txtick=xpm(1):((xpm(2)-xpm(1))/nx):xpm(2); %<21>
tytick=0:((210-0)/ny):210; %<22>
set(h_at,'Xtick',txtick,'Ytick',tytick,'FontSize',18) %<23>
set(gcf,'Position',[50 50 1200 1200],'Color','w')
export_fig('5.png','-r300');