matlab绘制双纵坐标图.doc_第1页
matlab绘制双纵坐标图.doc_第2页
matlab绘制双纵坐标图.doc_第3页
matlab绘制双纵坐标图.doc_第4页
matlab绘制双纵坐标图.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

MATLAB画双纵坐标具有两个纵坐标标度的图形在MATLAB中,如果需要绘制出具有不同纵坐标标度的两个图形,可以使用plotyy绘图函数。调用格式为:plotyy(x1,y1,x2,y2)其中x1,y1对应一条曲线,x2,y2对应另一条曲线。横坐标的标度相同,纵坐标有两个,左纵坐标用于x1,y1数据对,右纵坐标用于x2,y2数据对。双y轴坐标可以用plotyy(x,y1,x,y2)来实现双x坐标可以用set(gca,xaxislocation,bottom,xticklabel,0,1,2,3,4) (假设x轴的标注为1,2,3,4)set(gca,xaxislocation,top,xticklabel,0,1,2,3,4)进行相应的设置实现双纵坐标画图,其中一个为对数坐标,另一个为正常坐标。而且两个坐标的范围差别很大举例如下:t = 0:900; A = 1000; a = 0.005; b = 0.005;z1 = A*exp(-a*t);z2 = sin(b*t);haxes,hline1,hline2 = plotyy(t,z1,t,z2,semilogy,plot);/archiver/tid-738830.htmlmatlab作图里面如何分别设置双纵坐标的刻度?工作遇到如下问题:需要设置双y轴的刻度,用到以下函数,set(gca,XTick,0:5:100) set(gca,yTick,0:10:350) 只是设置左边的y轴刻度,请问各位高手,右边y轴怎么设置刻度标注?双纵坐标的标注已实现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轴的刻度/thread-42331-1-1.html双y坐标实例close all hiddenclear all clc% w=boxcar(nfft);fni1=input(请输入时间序列文件: ,s);fid1=fopen(fni1,r);s=fscanf(fid1,%s,1);if same(s,Curve)for i=1:61tline=fgetl(fid1);endelsefid1=fopen(fni1,r);enda1=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);MATLAB作图:plotyy使用方法。即:横坐标相同,纵坐标不同的两条曲线画在同一图上进行比对。例1. 需要采用图形句柄,详细内容参考MATLAB帮助文件有关plotyy的例程%This example graphs two mathematical functions using plot as the plotting function. The two y-axes%enable you to display both sets of data on one graph even though relative values of the data are quite%different.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);用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,:)-例2. 线型设置:t=0:.1:8;ax,h1,h2=plotyy(t,sin(t),t,cos(t);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 onx=linspace(0,2*pi,40);hh=line(x,cos(x);set(hh,linestyle,-)set(hh,marker,s)hold onhhf=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);坐标轴标注: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);/wang1901/blog/item/def559ed01535fd1b31cb103.htmlmatlab中如何显示plotyy的legend举例:ax,h1,h2=plotyy(x1,y1,x2,y2);hold on;h3=plot(x3,y3);legend(h1,h2,h3,a,b,c);即可!/chenlijia_just/blog/static/19

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论