Matlab的多个图像共享一个横坐标subplot、plotyy
x=0:0.1:7;
h1=subplot (3,1,1 );
plot(x,sin ) x )、' k ' );
H2=subplot (3,1,2 );
plot(x,cos ) x,' k ' );
set([H1,h2]、' Xcolor '、' w '、' XTick '、[] ) %将前两个x坐标设置为白色,不显示XTick
如果在plotyy中双轴显示相同的图像,则一方显示左y、下x,另一方显示右y、下x
H3=subplot (3,1,3 );
[ax,h4,H5]=plotYY(x,sec ) x,x,sec ) x );
复选框关闭
set(ax(1)、' YColor '、' k ' ) %k黑色
set(ax )2)、Xaxislocation、bottom、YColor和k
set(H5,' color ',' k ' ) ) ) )。
set(GCF,' color ',' w ' ) %将背景颜色设置为白色,间接隐藏所有白色轴
x=0:0.01:20;
y1=200*exp(-0.05*x ).*sin(x ) x;
y2=0.8*exp(-0.5*x ).*sin ) 10*x );
[AX,H1,H2]=
plotYY(x,y1,x,y2,' plot ' ); ylabel('first
axes1';
set(ax(1)、' ylim )、[-300 300]; %
坐标轴范围
set(ax )1)、' ytick ',[-300:100:300]
%坐标轴刻度被分割为这样多个范围set(ax(1)、' yticklabel '、[-300:100:300] )
set(ax(1)、' box '、' off ' ) ) ) )。
set(get ) ax(2)、' ylabel )、' string )、' Second axes2);
set(ax )2)、' ylim '、[-1 1];
set(ax )2)、' ytick )、[-1:5:1]
set(ax )2)、' yticklabel ',[-1:5:1] )
set(ax(2)、' xaxislocation '、' top ' ) %%%%%%坐标轴位置
在金融数据的制图中,正如一般的统计分析图那样,横轴上显示着日期,但你书中的方法只能将日期与原数字重叠。 另外,即使想尽办法也不能消除原来的数字。 例如,代码如下所示,为横坐标1
245怎么也去不了,用日期代替。 请多关照
A=[1 2 3 4 5]; B=[2 4 6 8
10 );
plotYY(1:5、a、1:5、b、' plot ' );
set(GCA,' XTick ',[ 1234 ]5];
set(GCA,' XTickLabel ',{'2005-01 ',' 2005-07 ',' 2006-01 ',
' 2006-07 ',' 2007-01'};
如图所示,横轴与数字重叠是因为x轴有两个
修改后:
A=[1 2 3 4 5]; B=[2 4 6 8
10 );
[axH1H2]=plotYY(1:5,a,1:5,b,' plot ' );
set(ax,' XTick ',[ 1234 ]5]; %
相当于刻度的坐标轴不是具有控件大小set(ax,) XTickLabel、({'2005-01 ),
' 2005-07 ',' 2006-01 ',' 2006-07 ',' 2007-01'};
%%以XTick为例
A=[1 2 3 4 5]; B=[2 4 6 8 10];
[axH1H2]=plotYY(1:5,a,1:5,b,' plot ' );
set(ax,' XTick ',[ 1234 ]5];
ma
tlab plotyy xtick的横坐标的设置问题[AX,H1,H2] = plotyy(24,0,0,0,'plot');
set(AX(1),'XColor','k','YColor','b');
set(AX(2),'XColor','k','YColor','r');
set(get(AX(1),'Ylabel'),'String','Plasma Glucose (mg/dl)')
set(get(AX(2),'Ylabel'),'String','Plasma Insulin (pmol/l)')
set(AX(1),'ylim',[50 250])
set(AX(2),'ylim',[0 600])
set(AX(1),'ytick',50:50:250)
set(AX(2),'ytick',0:100:600)
set(gca,'xlim',[0 24])
set(gca,'xtick',0:2:24)
grid on
xlabel('Time (hour)')
目的是想让左边的纵坐标范围为50-250,右边的纵坐标范围为0-600,横坐标范围为0-24
现在出来的图纵坐标没问题,但横坐标很乱,不知为什么。请高人指教。
倒数第三第四句:
set(gca,'xlim',[0 24])
set(gca,'xtick',0:2:24)
改成:
set(AX,'xlim',[0 24])
set(AX,'xtick',0:2:24)
原因:
这里有两个x轴,因此需要将两个的axes的x坐标设置成一样的才行
这些关键在于设置句柄
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
双纵坐标的标注已实现
[AX]=plotyy(x1,y1,x1,y2);
set(get(AX(1),'Ylabel'),'string','left
Y-axis‘);
set(get(AX(2),'Ylabel'),'string','right
y-axis');
了解plotyy的返回值
[AX]=plotyy(x1,y1,x1,y2);
得到两个axes句柄,AX(1)和AX(2)
set(AX(1),'yTick',[0:10:350]) 设置左边Y轴的刻度
set(AX(2),'yTick',[0:10:350]) 设置右边Y轴的刻度
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
双y坐标实例
close all hidden
clear all
clc
% w=boxcar(nfft);
fni1=input('请输入时间序列文件: ','s');
fid1=fopen(fni1,'r');
s=fscanf(fid1,'%s',1);
if same(s,'Curve')
for
i=1:61
tline=fgetl(fid1);
end
else
fid1=fopen(fni1,'r');
end
a1=fscanf(fid1,'%f');
status=fclose(fid1);
n=length(a1);
n2=n/2;
a2=reshape(a1,2,n2);
x1=a2(1,:);
y1=a2(2,:);
fni2=input('输入速度曲线文件','s');
fid2=fopen(fni2,'r');
b=fscanf(fid2,'%f');
n3=length(b);
n4=n3/2;
b2=reshape(b,2,n4);
x2=b2(1,:);
y2=b2(2,:);
p=polyfit(x2,y2,3);
y3=polyval(p,x2);
% plot(x2,y2)
[AX,H1,H2]=plotyy(x1,y1,x2,y3);
grid on;
xlabel('时间/s');
set(get(AX(1),'Ylabel'),'string','加速度/g');
set(get(AX(2),'Ylabel'),'string','速度km/h');
set(AX(1),'yTick',[-2:0.5:2]);
% % axes1 = axes('Position',[0.08 0.73 0.38
0.25],'Parent',figure1);
% axis(axes1,[0 xtime(end) -0.5 0.5]);
% set(AX(2),'YTick',[300:5:350]);
yticks2 = linspace(300,360,9);
set(AX(2),'YLim',[300 360],'YTick',yticks2);
set(H2,'linewidth',3);
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
[AX,H1,H2] = plotyy(x,y1,x,y2,'plot');
set(AX(1),'XColor','k','YColor','b');
set(AX(2),'XColor','k','YColor','r');
HH1=get(AX(1),'Ylabel');
set(HH1,'String','Left Y-axis');
set(HH1,'color','b');
HH2=get(AX(2),'Ylabel');
set(HH2,'String','Right Y-axis');
set(HH2,'color','r');
set(H1,'LineStyle','-');
set(H1,'color','b');
set(H2,'LineStyle',':');
set(H2,'color','r');
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.');
title('Labeling plotyy');
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
用[AX,H1,H2]=plotyy(x,y1,x,y2);命令。AX(1),AX(2)分别为左右Y轴的句柄
%%You can use the handles returned by plotyy to label the axes and
set the line styles used for plotting.
%%With the axes handles you can specify the YLabel properties of
the left- and right-side y-axis:
set(get(AX(1),'Ylabel'),'String','Slow Decay')
set(get(AX(2),'Ylabel'),'String','Fast Decay')
%%Use the xlabel and title commands to label the x-axis and add a
title:
xlabel('Time (musec)')
title('Multiple Decay Rates')
%%Use the line handles to set the LineStyle properties of the left-
and right-side plots:
set(H1,'LineStyle','--')
set(H2,'LineStyle',':')
、++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
linspace(0,2*pi,40) % 0到2pi之间布 40个点 生成1*40的行向量
legend([h1,h2,h3],'a','b','c');
这块用曲线的句柄给曲线进行标注 。这种方法允许挑选任意几条标注,而不用按着画图的顺序来。
Plotyy(x1,y1,x2,y2,
'function1','function2')------功能同上,function是指那些
绘图函数如:plot,semilogx,
loglog等. ...