matlab中双坐标轴画图
(2013-02-26 14:44:37)分类: 科学研究 |
例一:
set(H2,'Marker','o');
legend([H1,H2],'XXXX','YYYY');
例二:
clc
clear all
close all
runoff=[10700 11400 15800 22900 43100 40700 50500 46000 41800
35000];
sed=[0.105 0.094 0.156
1.264
m=1:10;
[ax,h1,h2]=plotyy(m,runoff,m,sed); %h-- line handle
set(get(ax(1),'Ylabel'),'string','Runoff (m^3/s))','color','r')
%y1
set(get(ax(2),'Ylabel'),'string','Sediment concentration
(kg/m^3)','color','k') %y2
xlabel('Month')
set(h1,'linestyle','-','color','r');
set(h2,'linestyle','- -','color','k');
legend([h1 h2],'runoff','sediment concentration') %标注两条线
legend('boxoff')
% box off
set(ax(:),'Ycolor','k') %设定两个Y轴的颜色为黑色
set(ax(1),'ytick',[0:10000:100000]); %设置y轴间隔
set(ax(2),'ytick',[0:0.1:1.5])
set(ax,'xlim',[1 12]) % 设置x轴范围
hold on
scatter(ax(1),4,22900,'r*')
axes(ax(2));
hold on
scatter(4,1.264,'ro')
set(gca, ’XTick’, [0 1 2])
set(gca,'XTickLabel',{'a','b','c'})
set(gca,'FontName','Times New Roman','FontSize',14)
对字体的设置也可以用在title, xlabel, ylabel等中
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
y3 = sin(x);
[AX,H1,H2] = plotyy(x,[y1;100*y3],x,[y3;y2],'plot');
************************************
对原图双坐标的某一坐标加曲线:
x=linspace(0,2*pi,40);
[ax,h1,h2]=plotyy(x,sin(x)+cos(x),x,exp(x));
set(h1,'linestyle','-')
set(h2,'linestyle','-')
set(h1,'marker','o')
set(h2,'marker','+')
hold on
x=linspace(0,2*pi,40);
hh=line(x,cos(x));
set(hh,'linestyle','-')
set(hh,'marker','s')
hold on
hhf=line(x,sin(x));
set(hhf,'color','r')
set(hhf,'linestyle','-')
set(hhf,'marker','*')
legend([h1,h2,hh,hhf],'sin(x)+cos(x)','exp(x)','cos(x)','sin(x)',0);
From:
********************************
my codes:
clear all
clc;
%**************
I = 0:0.005:4;
V1 = zeros(1,length(I));
Irr = 1000;
Temp = 25;
for i = 1:length(I)
end
P1=V1.*I;
%**************
I = 0:0.005:4;
V = zeros(1,length(I));
Irr = 300;
Temp = 25;
for i = 1:length(I)
end
P2=V2.*I;
%**************
figure(1);
[AX,H1,H2] = plotyy(V1,I,V1,P1);
set(H1,'LineStyle','-','LineWidth',4);
set(H1,'color','b');
set(H2,'LineStyle','-.','LineWidth',4);
set(H2,'color','b');
set(AX(1),'xlim',[0 45],'ylim',[0
5],'FontSize',40,'LineWidth',6,'Xcolor','k','Ycolor','k','FontName','Times
New Roman');
set(AX(2),'xlim',[0 45],'ylim',[0
65],'FontSize',40,'LineWidth',6,'Xcolor','k','Ycolor','k','FontName','Times
New Roman');
set(get(AX(1),'Ylabel'),'string','I
(A)','FontSize',40,'FontName','Times New Roman');
set(get(AX(2),'Ylabel'),'string','P
(W)','FontSize',40,'FontName','Times New Roman');
xlabel('V (V)');
set(AX(1),'ytick',[0:1:5]);
set(AX(2),'ytick',[0:13:65]);
hold on;
hhf1=plot(AX(1),V2,I);
set(hhf1,'color','k')
set(hhf1,'linestyle','-.','LineWidth',6)
hold(AX(2));
hhf2=plot(AX(2),V2,P2);
set(hhf2,'color','k')
set(hhf2,'linestyle',':','LineWidth',6)
hold on;
hhf3=plot(AX(1),V2+V1,I);
set(hhf3,'color','r')
set(hhf3,'linestyle','--','LineWidth',6)
hold on;
hhf4=plot(AX(2),V2+V1,P2+P1);
set(hhf4,'color','r')
set(hhf4,'linestyle',':','LineWidth',6)
grid off
Note: 可以先对AX1 和AX2分别画一条曲线,然后再用hold on; plot来对两坐标添加更多的曲线。