花如月 发表于 2007-10-8 21:40

双plotyy图形绘制的问题

绘图的代码如下:
clear;close all;
x1=-150:1:-0.00001;
x2=0.0001:1:16;
n=0:10;
=size(x1);
=size(x2);
for i=1:nn
    a1=(-1).^n.*((0.4-sqrt(1e4))/(0.4+sqrt(1e4))).^n.*(erfc((0.0032.*(n+1)-0.0001.*x1(1,i).*sqrt(1e-4))./(2*sqrt(10*1e-8)))+erfc((0.0032.*n-0.0001.*x1(1,i).*sqrt(1e-4))./(2*sqrt(10*1e-8))));
%%
    y1(1,i)=5.*(1-(0.4.*sqrt(1e-4)./(1+0.4*sqrt(1e-4))).*sum(a1));
end
for i=1:nn1
    a2=(-1).^n.*((0.4-sqrt(1e4))/(0.4+sqrt(1e4))).^n.*(erfc((0.0032.*n+0.0001.*x2(1,i))./(2*sqrt(10*1e-8)))-erfc((0.0032.*(n+1)-0.0001.*x2(1,i))./(2*sqrt(10*1e-8))));
    y2(1,i)=5.*((0.4/(1+0.4*sqrt(1e-4))).*sum(a2));
end
x11=-150:1:-0.00001;
x12=0.0001:1:16;
n=0:10;
=size(x11);
=size(x12);
for i=1:nn
   a11=(-1).^n.*((0.2-sqrt(1e4))/(0.2+sqrt(1e4))).^n.*(erfc((0.0032.*(n+1)-0.0001.*x11(1,i).*sqrt(1e-4))./(2*sqrt(10*1e-8)))+erfc((0.0032.*n-0.0001.*x11(1,i).*sqrt(1e-4))./(2*sqrt(10*1e-8))));
y11(1,i)=5.*(1-(0.2.*sqrt(1e-4)./(1+0.2*sqrt(1e-4))).*sum(a11));
end
for i=1:nn1
    a12=(-1).^n.*((0.2-sqrt(1e4))/(0.2+sqrt(1e4))).^n.*(erfc((0.0032.*n+0.0001.*x12(1,i))./(2*sqrt(10*1e-8)))-erfc((0.0032.*(n+1)-0.0001.*x12(1,i))./(2*sqrt(10*1e-8))));
    y12(1,i)=5.*((0.2/(1+0.2*sqrt(1e-4))).*sum(a12));
end
=plotyy(x11,y11,x12,y12);
hold on
= plotyy(x1,y1,x2,y2,'plot')
set(H1,'LineStyle','--','color','r','linewidth',2)
set(H2,'LineStyle',':','color','r','linewidth',2)可以看出绘制的图,右边的y轴标注重叠。另外由于用了hold on,致使前后2个plotyy的坐标系统完全独立(从右边y轴的标注可以看出来)。目的是想让第二次的plotyy在第一个plotyy产生的坐标里绘图,也就是让他们的坐标一致。该如何设置呢?看了plotyy的doc文档,里边只有设置ylabel的方法。set(get(AX(1),'Ylabel'),'String','Left Y-axis')set(get(AX(2),'Ylabel'),'String','Right Y-axis');但是没有设置其他参数的方法,求高手帮忙。

plot是可以绘制但是效果不好:@( ,附图里的正确曲线走势是用plot绘制的

[ 本帖最后由 无水1324 于 2007-10-8 22:05 编辑 ]

eight 发表于 2007-10-8 21:50

看得不是太懂,你看看以下帖子 bainhome 所贴的代码是否对你有帮助:
http://forum.vibunion.com/forum/viewthread.php?tid=24244

无水1324 发表于 2007-10-8 22:01

回复 #2 eight 的帖子

与他这个有点差异,主要是右边的要重合在一起

xray 发表于 2007-10-8 22:09

回复 #1 花如月 的帖子

试试这个

=plotyy([ x11.'x1.' ], , , );

花如月 发表于 2007-10-8 22:09

bainhome 太强了,正在消化他的代码。不过正如楼上所说,他是在一个图中建立了多个axes。然后把位置错开分别绘图,这里是2个plotyy有4个y轴。主要是想让2个plotyy共用一个axes,用hold on后他们的axes是独立的,才导致重合和曲线不对的问题

花如月 发表于 2007-10-8 22:13

回复 #4 xray 的帖子

多谢,在help文档里并没有看到这种调用的格式。你在哪儿看到的?

xray 发表于 2007-10-8 22:22

回复 #6 花如月 的帖子

help plot
    PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix,
    then the vector is plotted versus the rows or columns of the matrix,
    whichever line up.

说明:
1. plot 和 plotyy 绘图的原理是一样的
2. 当plot的输入是矩阵时,在同一坐标轴内分别绘制各个列向量

无水1324 发表于 2007-10-9 15:38

回复 #7 xray 的帖子

谢谢,高手 !
看来我学的东西不会变通哈
页: [1]
查看完整版本: 双plotyy图形绘制的问题