MATLAB学习笔记 plotyy双y轴

一、线型设置:

t=0:0.1:8;
[ax,h1,h2]=plotyy(t,sin(t),t,cos(t)); % plotyy(X1,Y1,X2,Y2):以左、右不同纵轴绘制X1-Y1、X2-Y2两条曲线。
set(h1,'linestyle','-','marker','o','color','r');
set(h2,'linestyle',':','marker','x','color','b');

二、加注图例:

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); %加注多条线的图例

用法:linspace(x1,x2,N)  

功能:linspace是Matlab中的一个指令,用于产生x1,x2之间的N点行矢量。其中x1、x2、N分别为起始值、中止值、元素个数。若缺省N,默认点数为100。

三、坐标轴标注:

figure;
t=0:.1:3*pi;
[H,Ha,Hb]=plotyy(t,sin(t),t,exp(t));
d1=get(H(1),'ylabel');
set(d1,'string','yayacpf');
d2=get(H(2),'ylabel');
set(d2,'string','bbs from hit','fontsize',18);

四、双坐标轴

X=[10,30,50,70,100,150,200];
Y1=[0.0501,0.1847,0.1663,0.235,0.2724,0.3491,0.3856];
Y2=[0.0239,0.0545,0.1165,0.1003,0.1413,0.2381,0.2433];
[AX,H1,H2]=plotyy(X,Y1,X,Y2,'plot','plot'); %双y轴图像
xlabel('User ID');
set(get(AX(1),'ylabel'),'string','Average Trust Value');  %对坐标标注
set(get(AX(2),'ylabel'),'string','Normalized NTR, NBTR, NREJ');
set(AX(1),'ytick',[0:0.1:1]);               %控制左边的y轴的刻度标注
set(AX(2),'ytick',[0:0.1:1]);  
set(H1,'marker','*');
set(H2,'marker','o');
set(H2,'LineStyle','none')
legend('Average Trust Value','NTR');

五、legend函数

legend(字符串1,字符串2,字符串3,…,参数)  

参数字符串的含义如下表所示:

参数字符串                                      含  义  
    0                            尽量不与数据冲突,自动放置在最佳位置  

    1                                      放置在图形的右上角  

    2                                      放置在图形的左上角  

    3                                      放置在图形的左下角  

    4                                      放置在图形的右下角  

   -1                                    放置在图形视窗的外右边 

参考:

https://blog.csdn.net/u010555688/article/details/37723559

http://blog.sina.com.cn/s/blog_59a069d50101lcdh.html

http://blog.sina.com.cn/s/blog_4d66c6ca0100jdjh.html

猜你喜欢

转载自blog.csdn.net/weixin_40695510/article/details/81270648
今日推荐