1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
comment
xlogplot, xylogplot defined
endcomment
function xticks (aa=0,bb=0)
if argn==2; a=aa; b=bb;
elseif argn==1; a=min(aa); b=max(aa);
else error("Wrong arguments for ticks");
endif;
if (b>1e30); b=1e30; endif;
if (a<-1e30); a=-1e30; endif;
if (a>=b); b=a+1; endif;
tick=10^floor(log(b-a)/log(10)-0.4);
if b-a>10*tick; tick1=tick*2; else; tick1=tick; endif;
if (tick>0.001) && (tick<1000); tick=1; endif;
return (floor(a/tick1))*tick1:tick1:(ceil(b/tick1))*tick1;
endfunction;
function xlogticks(expi,expf,base)
x=[ ];
for k = floor(expi) to floor(expf);
x = x | logbase(1:base,base) + k;
end;
return x;
endfunction;
function xlogplot(x=1,y=0,xbase=10)
## xlogplot draws y(x) in a semilog paper with base xbase
if argn()==0;
p=plot();
else
if !holding();clg;endif;
if iscomplex(x); xe=abs(x); else xe=x; endif;
if iscomplex(y); ye=abs(y); else ye=y; endif;
xl=logbase(xe,xbase);
expi=floor(logbase(min(xe),xbase));
expf=ceil(logbase(max(xe),xbase));
xt=xlogticks(expi,expf,xbase);
yt=xticks(min(ye),max(ye));
p=setplot([expi,expf,min(yt),max(yt)]);
h=textheight();w=textwidth();
hd=holding(1);
ls=linestyle(".");
lw=linewidth(1);
c=color(1);
for i=1 to length(yt);
plot([expi,expf],[yt[i],yt[i]]);
d=toscreen([expi,yt[i]]);
rtext(printf("%g",yt[i]),[d[1]-w,d[2]-h/2]);
end;
for i=1 to length(xt)-10;
plot([xt[i],xt[i]],[p[3],p[4]]);
end;
for i=expi to expf;
d=toscreen([i,p[3]]);
.. ctext(printf("%g",xbase)|"^"|printf("%g",i),[d[1],d[2]+h/2]);
rtext(printf("%g",xbase),[d[1]+w,d[2]+0.75*h]);
text(printf("%g",i),[d[1]+w,d[2]+h/4]);
end;
color(c);
linewidth(lw);
linestyle(ls);
plot(xl,ye);
holding(hd);
endif;
return p;
endfunction;
function ylogplot(x=0,y=1,ybase=10)
## xlogplot draws y(x) in a semilog paper with base ybase
if argn()==0;
p=plot();
else
if !holding();clg;endif;
if iscomplex(x); xe=abs(x); else xe=x; endif;
if iscomplex(y); ye=abs(y); else ye=y; endif;
yl=logbase(ye,ybase);
expi=floor(logbase(min(ye),ybase));
expf=ceil(logbase(max(ye),ybase));
xt=xticks(min(xe),max(xe));
yt=xlogticks(expi,expf,ybase);
p=setplot([min(xt),max(xt),expi,expf]);
h=textheight();w=textwidth();
hd=holding(1);
ls=linestyle(".");
lw=linewidth(1);
c=color(1);
for i=1 to length(yt)-10;
plot([p[1],p[2]],[yt[i],yt[i]]);
end;
for i=expi to expf;
d=toscreen([p[1],i]);
.. rtext(printf("%g",ybase)|"^"|printf("%g",i),[d[1]-w/2,d[2]-h/2]);
rtext(printf("%g",ybase),[d[1]-40,d[2]-h/2]);
text(printf("%g",i),[d[1]-40,d[2]-h]);
end;
for i=1 to length(xt);
plot([xt[i],xt[i]],[p[3],p[4]]);
d=toscreen([xt[i],p[3]]);
ctext(printf("%g",xt[i]),[d[1],d[2]+h/2]);
end;
color(c);
linewidth(lw);
linestyle(ls);
plot(xe,yl);
holding(hd);
endif;
return p;
endfunction;
function xylogplot(x=1,y=1,xbase=10,ybase=10)
## xylogplot draws y(x) in a loglog paper with base xbase and ybase
if argn()==0;
p=plot();
else
if !holding();clg;endif;
if iscomplex(x); xe=abs(x); else xe=x; endif;
if iscomplex(y); ye=abs(y); else ye=y; endif;
xl=logbase(xe,xbase);
yl=logbase(ye,ybase);
expix=floor(logbase(min(xe),xbase));
expfx=ceil(logbase(max(xe),xbase));
expiy=floor(logbase(min(ye),ybase));
expfy=ceil(logbase(max(ye),ybase));
xt=xlogticks(expix,expfx,xbase);
yt=xlogticks(expiy,expfy,ybase);
p=setplot([expix,expfx,expiy,expfy]);
h=textheight();w=textwidth();
hd=holding(1);
ls=linestyle(".");
lw=linewidth(1);
c=color(1);
for i=1 to length(xt)-10;
plot([xt[i],xt[i]],[p[3],p[4]]);
end;
for i=expix to expfx;
d=toscreen([i,p[3]]);
.. ctext(printf("%g",xbase)|"^"|printf("%g",i),[d[1],d[2]+h/2]);
rtext(printf("%g",xbase),[d[1]+w,d[2]+0.75*h]);
text(printf("%g",i),[d[1]+w,d[2]+h/4]);
end;
for i=1 to length(yt)-10;
plot([p[1],p[2]],[yt[i],yt[i]]);
end;
for i=expiy to expfy;
d=toscreen([p[1],i]);
.. rtext(printf("%g",ybase)|"^"|printf("%g",i),[d[1]-w/2,d[2]-h/2]);
rtext(printf("%g",ybase),[d[1]-40,d[2]-h/2]);
text(printf("%g",i),[d[1]-40,d[2]-h]);
end;
color(c);
linewidth(lw);
linestyle(ls);
plot(xl,yl);
holding(hd);
endif;
return p;
endfunction;
|