## Asymptote using graph.asy – fig0010

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 3 h 10 min

 (Compiled with Asymptote version 2.14svn-r5318)

size(8cm,0,false);
import graph;

xlimits(0, 200);
ylimits(-50, 50);
yaxis("y-value");
xaxis("x-value");



Étiquettes : ,

## Asymptote using graph.asy – fig0020

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 4 h 10 min

 (Compiled with Asymptote version 2.14svn-r5318)

size(8cm,0,false);
import graph;

xlimits(0, 200);
ylimits(-50, 50);
yaxis( "y-value", Left);
xaxis( "x-value", Bottom(true));



Étiquettes : ,

## Asymptote using graph.asy – fig0030

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 5 h 10 min

 (Compiled with Asymptote version 2.14svn-r5318)

size(8cm,0,false);
import graph;

xlimits( -100, 100);
ylimits( -50, 50);
yaxis( "y" , RightTicks());
xaxis( "x", Ticks());



Étiquettes : ,

## Asymptote using graph.asy – fig0040

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 6 h 10 min

 (Compiled with Asymptote version 2.14svn-r5318)

size(8cm,0);
import graph;

xlimits( -100, 100);
ylimits( -50, 50);
yaxis( "$y$" , Ticks(Label(currentpen+fontsize(8),align=E)));
xaxis( "$x$", Ticks(Label(currentpen+fontsize(8))));



Étiquettes : ,

## Asymptote using graph.asy – fig0050

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 7 h 10 min

 (Compiled with Asymptote version 2.14svn-r5318)

size(8cm,0);
import graph;

xlimits( -100, 100);
ylimits( -50, 50);

defaultpen(overwrite(SuppressQuiet));

yaxis( "$y$" , Ticks(Label(.8red+fontsize(8),align=E)), p=.8red);
xaxis( "$x$", Ticks(Label(.8blue+fontsize(8))), p=.8blue);



Étiquettes : , ,

## Asymptote using graph.asy – fig0060

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 8 h 10 min

 (Compiled with Asymptote version 2.14svn-r5318)

size(8cm,0);
import graph;

xlimits( -3pi, 3pi);
ylimits( -5, 5);
yaxis( "y" , LeftRight(), RightTicks(pTick=.8red, ptick=lightgrey, extend=true));
xaxis( "x-value", BottomTop(), Ticks(Label("$%.2f$",red), Step=2pi, step=pi/5, pTick=.8red, ptick=lightgrey, extend=true));



Étiquettes : , ,

## Asymptote using graph.asy – fig0070

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 9 h 10 min

 (Compiled with Asymptote version 2.14svn-r5318)

size(8cm,0);
import graph;

xlimits( -3pi, 3pi);
xaxis(BottomTop(), Ticks(Label("$%.2f$",red), Step=2pi, step=pi/5, pTick=.8red));



Étiquettes : , ,

## Asymptote using graph.asy – fig0080

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 10 h 10 min

 (Compiled with Asymptote version 2.14svn-r5318)

size(8cm,0);
import graph;
texpreamble("\usepackage[frenchb]{babel}");

xlimits( -3pi, 3pi);
xaxis(BottomTop(), Ticks(Label("$\nombre{%.2f}$",red), Step=2pi, step=pi/5, pTick=.8red));



Étiquettes : , , ,

## Asymptote using graph.asy – fig0090

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 11 h 10 min

 (Compiled with Asymptote version 2.14svn-r5318)

size(8cm,0);
import graph;
texpreamble("\usepackage[frenchb]{babel}");

xlimits( -10000, 10000);
xaxis(BottomTop(), Ticks(Label("$\nombre{%0.f}$",red), Step=5000, step=500, pTick=.8red));



Étiquettes : , , ,

## Asymptote using graph.asy – fig0110

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 12 h 10 min

 (Compiled with Asymptote version 2.14svn-r5318)

// An other solution...
size(8cm,0);
import graph;
usepackage("icomma");

xlimits( -3pi, 3pi);

xaxis(Ticks(Label(red), Step=2pi,step=pi/5,pTick=.8red));



Étiquettes : , , ,

## Asymptote using graph.asy – fig0120

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 13 h 10 min

 (Compiled with Asymptote version 2.14svn-r5318)

size(6cm,0);
import graph;

xlimits( -3, 3);
ylimits( -3, 3);
xaxis(Ticks("%"));
yaxis(Ticks("%"));

labelx(1,2S);
labely(1,2W);
labelx("$O$",0,SW);
dot((0,0));



Étiquettes : , ,

## Asymptote using graph.asy – fig0130

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 14 h 10 min

 (Compiled with Asymptote version 2.14svn-r5318)

import graph;

unitsize(x=1cm);
real f(real x){return x;}
xlimits( -3, 3);
ylimits( -3, 3);
draw(graph(f,-3,3));
xaxis(Label("$x$",position=EndPoint, align=SE),Ticks("%",extend=true), Arrow);
yaxis(Label("$y$",position=EndPoint, align=NW),Ticks("%",extend=true), Arrow);

labelx(1,2S);
labely(1,2W);
labelx("$O$",0,SE);
dot((0,0));



Étiquettes : , ,

## Asymptote using graph.asy – fig0140

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 15 h 10 min

 (Compiled with Asymptote version 1.84svn-r4619)

unitsize(x=1cm);
import graph;

xlimits( -3, 2);
ylimits( -3, 3);
xaxis(xmin=-3, xmax=2,Ticks("%"));
yaxis(ymin=-3, ymax=3, Ticks("%"));

labelx(1,2S);
labely(1,2W);
labelx("$O$",0,SW);
dot((0,0));
draw(Label("$x$",position=Relative(1),align=2S),(currentpicture.userMin().x-1,0)--(currentpicture.userMax().x+1,0),Arrow);
draw(Label("$y$",position=Relative(1),align=2W),(0,currentpicture.userMin().y-1)--(0,currentpicture.userMax().y+1),Arrow);



Étiquettes : , ,

## Asymptote using graph.asy – fig0150

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 16 h 10 min

 (Compiled with Asymptote version 2.14svn-r5318)

import graph;
unitsize(1cm);

xlimits( -3, 2);
ylimits( -3, 3);
xaxis("$x$",Ticks("%",begin=false, end=false),arrow=Arrow);
yaxis("$y$",Ticks("%",begin=false, end=false),arrow=Arrow);

labelx(1,2S);
labely(1,2W);
labelx("$O$",0,SW);
dot((0,0));



Étiquettes : , ,

## Asymptote using graph.asy – fig0160

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 17 h 10 min

 (Compiled with Asymptote version 2.14svn-r5318)

import graph;
unitsize(1cm);

xlimits( -3, 2);
ylimits( -3, 3);
xaxis("$x$",Ticks(ticklabel=NoZeroFormat,1bp+red,end=false),arrow=Arrow);
yaxis("$y$",Ticks(ticklabel=NoZeroFormat,1bp+red,end=false),arrow=Arrow);

labelx(scale(.75)*"$O$",0,SW);



Étiquettes : , ,

## Asymptote using graph.asy – fig0170

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 18 h 10 min

 (Compiled with Asymptote version 2.14svn-r5318)

import graph;
unitsize(1cm);

xlimits( -3, 2);
ylimits( -3, 3);
xaxis("$x$",Ticks(modify=NoZero,1bp+red,end=false),arrow=Arrow);
yaxis("$y$",Ticks(modify=NoZero,1bp+red,end=false),arrow=Arrow);

labelx(scale(.75)*"$O$",0,SW);



Étiquettes : , ,

## Asymptote using graph.asy – fig0180

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 19 h 10 min

 (Compiled with Asymptote version 2.14svn-r5318)

import graph;
unitsize(1cm);

xlimits( -3, 2);
ylimits( -3, 3);

xaxis("$x$", Ticks(ticklabel=OmitFormat(-2,-1,2),
modify=NoZero,
1bp+red,
end=false),
arrow=Arrow);

yaxis("$y$", Ticks(ticklabel=OmitFormat(-2,-1,2,3),
modify=NoZero,
1bp+red,
end=false),
arrow=Arrow);

labelx(scale(.75)*"$O$",0,SW);



Étiquettes : , ,

## Asymptote using graph.asy – fig0190

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 20 h 10 min

 (Compiled with Asymptote version 2.14svn-r5318)

import graph;
unitsize(x=1cm, y=1.5cm);

xlimits( -3, 2);
ylimits( -2, 2);
xaxis(BottomTop, Ticks("%",extend=true, ptick=lightgrey));
yaxis(LeftRight, Ticks("%",extend=true, ptick=lightgrey));
xequals(Label("$y$",align=2NW),0,ymin=-2.5, ymax=2.5, p=linewidth(1.5pt), Arrow(2mm));
yequals(Label("$x$",align=2SE),0,xmin=-3.5, xmax=2.5, p=linewidth(1.5pt), Arrow(2mm));
labelx(Label("$1$",UnFill), 1);
labely(Label("$1$",UnFill), 1);
labelx("$O$",0,SW);
dot((0,0));



Étiquettes : , , ,

## Asymptote using graph.asy – fig0200

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 21 h 10 min

 (Compiled with Asymptote version 1.84svn-r4619)

import graph;

void graphicrules(picture pic=currentpicture, string prefix=defaultfilename, real unit=1cm,
real xunit=unit != 0 ? unit : 0,
real yunit=unit != 0 ? unit : 0,
real xmin, real xmax, real ymin, real ymax)
{
xlimits(xmin, xmax);
ylimits(ymin, ymax);
unitsize(x=xunit, y=yunit);
}

void grid(picture pic=currentpicture,
real xmin=pic.userMin().x, real xmax=pic.userMax().x,
real ymin=pic.userMin().y, real ymax=pic.userMax().y,
real xStep=1, real xstep=.5,
real yStep=1, real ystep=.5,
pen pTick=nullpen, pen ptick=grey, bool above=false)
{
draw(pic,box((xmin,ymin),(xmax,ymax)),invisible);
xaxis(pic, BottomTop, xmin, xmax, Ticks("%",extend=true,Step=xStep,step=xstep,pTick=pTick,ptick=ptick), above=above);
yaxis(pic, LeftRight, ymin, ymax, Ticks("%",extend=true,Step=yStep,step=ystep,pTick=pTick,ptick=ptick), above=above);
}

void cartesianaxis(picture pic=currentpicture,
Label Lx=Label("$x$",align=S),
Label Ly=Label("$y$",align=W),
real xmin=pic.userMin().x, real xmax=pic.userMax().x,
real ymin=pic.userMin().y, real ymax=pic.userMax().y,
real extrawidth=1, real extraheight=extrawidth,
pen p=currentpen,
ticks xticks=Ticks("%",pTick=nullpen, ptick=grey),
ticks yticks=Ticks("%",pTick=nullpen, ptick=grey),
bool above=true,
arrowbar arrow=Arrow)
{
extraheight= cm*extraheight/(2*pic.yunitsize);
extrawidth = cm*extrawidth/(2*pic.xunitsize);
yequals(pic, Lx, 0, xmin-extrawidth, xmax+extrawidth, p, above, arrow=arrow);
xequals(pic, Ly, 0, ymin-extraheight, ymax+extraheight, p, above, arrow=arrow);
yequals(pic, 0, xmin, xmax, p, xticks, above);
xequals(pic, 0, ymin, ymax, p, yticks, above);
}

void labeloij(picture pic=currentpicture,
Label Lo=Label("$O$",NoFill),
Label Li=Label("$\vec{\imath}$",NoFill),
Label Lj=Label("$\vec{\jmath}$",NoFill),
pair diro=SW, pair diri=S, pair dirj=W,
pen p=scale(2)*currentpen,
filltype filltype=NoFill, arrowbar arrow=Arrow(2mm))
{
if (Lo.filltype==NoFill) Lo.filltype=filltype;
if (Li.filltype==NoFill) Li.filltype=filltype;
if (Lj.filltype==NoFill) Lj.filltype=filltype;
labelx(pic, Lo, 0, diro, p);
draw(pic, Li, (0,0)--(1,0), diri, p, arrow);
draw(pic, Lj, (0,0)--(0,1), dirj, p, arrow);
dot(pic, (0,0), dotsize(p)+p);
}

//The figure starts here
graphicrules(yunit=1.5cm, xmin=-3, xmax=3, ymin=-2, ymax=2);
grid();
cartesianaxis(arrow=None);
labeloij(UnFill);



Étiquettes : , , , ,

## Asymptote using graph.asy – fig0340

Category: Asymptote,Examples 2D,graph.asyPh. Ivaldi @ 11 h 10 min

 (Compiled with Asymptote version 2.14svn-r5318)

//Author: John Bowman
import graph;
size(2cm, 0);
xlimits(0, 100);
ylimits(-50, 50);
yaxis( "y-value" ,Left, Courier("m", "n") + fontsize(12), RightTicks("%.4g"));



Étiquettes : , ,

## Asymptote using graph3.asy – fig0100

Category: Asymptote,Examples 3D,graph3.asyPh. Ivaldi @ 12 h 11 min

 (Compiled with Asymptote version 1.92svn-r4817)

// From documentation of Asymptote
import graph;
import palette;
import contour;
texpreamble("\usepackage{icomma}");

size(10cm,10cm,IgnoreAspect);

pair a=(0,0);
pair b=(5,10);

real fz(pair z) {
return z.x*z.y*exp(-z.x);
}
real f(real x, real y) {return fz((x,y));}

int N=200;
int Divs=10;
int divs=2;

defaultpen(1bp);
pen Tickpen=black;
pen tickpen=gray+0.5*linewidth(currentpen);
pen[] Palette=BWRainbow();

scale(false);

bounds range=image(f,Automatic,a,b,N,Palette);

xaxis("$x$",BottomTop,LeftTicks(pTick=grey, ptick=invisible, extend=true));
yaxis("$y$",LeftRight,RightTicks(pTick=grey, ptick=invisible, extend=true));

// Major contours
real[] Cvals;
Cvals=sequence(11)/10 * (range.max-range.min) + range.min;
draw(contour(f,a,b,Cvals,N,operator ..),Tickpen);

// Minor contours
real[] cvals;
real[] sumarr=sequence(1,divs-1)/divs * (range.max-range.min)/Divs;
for (int ival=0; ival < Cvals.length-1; ++ival)
cvals.append(Cvals[ival]+sumarr);
draw(contour(f,a,b,cvals,N,operator ..),tickpen);

palette("$f(x,y)=xye^{-x}$",range,point(NW)+(0,1),point(NE)+(0,0.25),Top,Palette,
PaletteTicks(N=Divs,n=divs,Tickpen,tickpen));



Étiquettes : , , , , ,

## Unofficial package graph_pi.asy – fig0010

Category: Asymptote,graph_pi.asy,Unofficial packagesPh. Ivaldi @ 5 h 50 min

 (Compiled with Asymptote version 2.14svn-r5318)

import graph_pi;

graphicrules(yunit=1.5cm, xmin=-3, xmax=3, ymin=-2, ymax=2);
grid();
cartesianaxis(arrow=None);
labeloij(UnFill);



Étiquettes : , ,

## Unofficial package graph_pi.asy – fig0020

Category: Asymptote,graph_pi.asy,Unofficial packagesPh. Ivaldi @ 6 h 50 min

 (Compiled with Asymptote version 2.14svn-r5318)

import graph_pi;

graphicrules(yunit=1.5cm, xmin=-3, xmax=3, ymin=-2, ymax=2);
grid(pic=currentpicture,
xmin=-3, xmax=3,
ymin=-2, ymax=2,
xStep=1, xstep=.1,
yStep=1, ystep=.1,
pTick=.8red, ptick=.8green,
above=false);
cartesianaxis(pic=currentpicture,
Lx=Label(scale(2)*"$x$",align=NW),
Ly=Label("$y$",align=SE),
xmin=-3, xmax=3,
ymin=-2, ymax=2,
extrawidth=5, extraheight=5,
p=currentpen,
xticks=Ticks("%",pTick=1mm+yellow, ptick=grey),
yticks=NoTicks,
viewxaxis=true,
viewyaxis=false,
above=true,
arrow=Arrow);
labeloIJ(pic=currentpicture,
Lo=Label("$O$",NoFill),
LI=Label("$I$",white,Fill(black)),
LJ=Label(" "),
diro=NE, dirI=N, dirJ=E,
p=blue,
filltype=NoFill,
marker=dot(2mm+red));



Étiquettes : , ,

## Unofficial package graph_pi.asy – fig0030

Category: Asymptote,graph_pi.asy,Unofficial packagesPh. Ivaldi @ 7 h 50 min

 (Compiled with Asymptote version 2.14svn-r5318)

import graph_pi;
size(200,0);
graphicrules(xmin=-1, xmax=4, ymin=-1, ymax=3);

grid(xstep=0,ystep=0);

cartesianaxis(xticks=Ticks(Label(Fill(white)), NoZero, ptick=invisible),
yticks=Ticks(Label(Fill(white)), NoZero, ptick=invisible));

labelx("$O$",0,SW);

shipout(bbox(Fill(white)));



Étiquettes : , ,

## Official Asymptote example – Bode

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 9 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph;
texpreamble("\def\Arg{\mathop {\rm Arg}\nolimits}");

size(10cm,5cm,IgnoreAspect);

real ampl(real x) {return 2.5/(1+x^2);}
real phas(real x) {return -atan(x)/pi;}

scale(Log,Log);
draw(graph(ampl,0.01,10));
ylimits(0.001,100);

xaxis("$\omega\tau_0$",BottomTop,LeftTicks);
yaxis("$|G(\omega\tau_0)|$",Left,RightTicks);

picture q=secondaryY(new void(picture pic) {
scale(pic,Log,Linear);
draw(pic,graph(pic,phas,0.01,10),red);
ylimits(pic,-1.0,1.5);
yaxis(pic,"$\Arg G/\pi$",Right,red,
LeftTicks("$% #.1f$",
begin=false,end=false));
yequals(pic,1,Dotted);
});
label(q,"(1,0)",Scale(q,(1,0)),red);



Étiquettes : , , ,

## Official Asymptote example – alignedaxis

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 4 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph;

real Freq=60.0;
real margin=5mm;

pair exp(pair x) {
return exp(x.x)*(cos(x.y)+I*sin(x.y));
}

real Merr(real x, real w) {
real tau=x/(2*Freq);
return 20*log(abs((tau*w+tau/(exp(I*2*pi*Freq*tau)-1))*(I*2*pi*Freq)));
}

real Aerr(real x, real w) {
real tau=x/(2*Freq);
return degrees((tau*w+tau/(exp(I*2*pi*Freq*tau)-1))*(I*2*pi*Freq));
}

picture pic1;
scale(pic1,Log,Linear);
real Merr1(real x){return Merr(x,1);}
draw(pic1,graph(pic1,Merr1,1e-4,1),black+1.2);

ylimits(pic1,-60,20);
yaxis(pic1,"magnitude (dB)",LeftRight,RightTicks(new
real[] {-60,-40,-20,0,20}));
xaxis(pic1,"$f/f_\mathrm{Ny}$",BottomTop,LeftTicks(N=5));
yequals(pic1,0,Dotted);
yequals(pic1,-20,Dotted);
yequals(pic1,-40,Dotted);
xequals(pic1,1e-3,Dotted);
xequals(pic1,1e-2,Dotted);
xequals(pic1,1e-1,Dotted);

size(pic1,100,100,point(pic1,SW),point(pic1,NE));

label(pic1,"$\theta=1$",point(pic1,N),2N);

frame f1=pic1.fit();

picture pic1p;
scale(pic1p,Log,Linear);
real Aerr1(real x){return Aerr(x,1);}
draw(pic1p,graph(pic1p,Aerr1,1e-4,1),black+1.2);

ylimits(pic1p,-5,95);
yaxis(pic1p,"phase (deg)",LeftRight,RightTicks(new real[] {0,45,90}));
xaxis(pic1p,"$f/f_\mathrm{Ny}$",BottomTop,LeftTicks(N=5));
yequals(pic1p,0,Dotted);
yequals(pic1p,45,Dotted);
yequals(pic1p,90,Dotted);
xequals(pic1p,1e-3,Dotted);
xequals(pic1p,1e-2,Dotted);
xequals(pic1p,1e-1,Dotted);

size(pic1p,100,100,point(pic1p,SW),point(pic1p,NE));

frame f1p=pic1p.fit();
f1p=shift(0,min(f1).y-max(f1p).y-margin)*f1p;

picture pic2;
scale(pic2,Log,Linear);
real Merr2(real x){return Merr(x,0.75);}
draw(pic2,graph(pic2,Merr2,1e-4,1),black+1.2);

ylimits(pic2,-60,20);
yaxis(pic2,"magnitude (dB)",LeftRight,RightTicks(new
real[] {-60,-40,-20,0,20}));
xaxis(pic2,"$f/f_\mathrm{Ny}$",BottomTop,LeftTicks(N=5));
yequals(pic2,0,Dotted);
yequals(pic2,-20,Dotted);
yequals(pic2,-40,Dotted);
xequals(pic2,1e-3,Dotted);
xequals(pic2,1e-2,Dotted);
xequals(pic2,1e-1,Dotted);

size(pic2,100,100,point(pic2,SW),point(pic2,NE));

label(pic2,"$\theta=0.75$",point(pic2,N),2N);

frame f2=pic2.fit();
f2=shift(max(f1).x-min(f2).x+margin)*f2;

picture pic2p;
scale(pic2p,Log,Linear);
real Aerr2(real x){return Aerr(x,0.75);}
draw(pic2p,graph(pic2p,Aerr2,1e-4,1),black+1.2);

ylimits(pic2p,-5,95);
yaxis(pic2p,"phase (deg)",LeftRight,RightTicks(new real[] {0,45.1,90}));
xaxis(pic2p,"$f/f_\mathrm{Ny}$",BottomTop,LeftTicks(N=5));
yequals(pic2p,0,Dotted);
yequals(pic2p,45,Dotted);
yequals(pic2p,90,Dotted);
xequals(pic2p,1e-3,Dotted);
xequals(pic2p,1e-2,Dotted);
xequals(pic2p,1e-1,Dotted);

size(pic2p,100,100,point(pic2p,SW),point(pic2p,NE));

frame f2p=pic2p.fit();
f2p=shift(max(f1p).x-min(f2p).x+margin,min(f2).y-max(f2p).y-margin)*f2p;



Étiquettes : , ,

## Official Asymptote example – brokenaxis

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 11 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph;

size(200,150,IgnoreAspect);

// Break the x axis at 3; restart at 8:
real a=3, b=8;

// Break the y axis at 100; restart at 1000:
real c=100, d=1000;

scale(Broken(a,b),BrokenLog(c,d));

real[] x={1,2,4,6,10};
real[] y=x^4;

draw(graph(x,y),red,MarkFill[0]);

xaxis("$x$",BottomTop,LeftTicks(Break(a,b)));
yaxis("$y$",LeftRight,RightTicks(Break(c,d)));

label(rotate(90)*Break,(a,point(S).y));
label(rotate(90)*Break,(a,point(N).y));
label(Break,(point(W).x,ScaleY(c)));
label(Break,(point(E).x,ScaleY(c)));



Étiquettes : ,

## Official Asymptote example – diatom

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 11 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph;

size(15cm,12cm,IgnoreAspect);

real minpercent=20;
real ignorebelow=0;
string data="diatom.csv";
string[] group;
int[] begin,end;

defaultpen(fontsize(8pt)+overwrite(MoveQuiet));

file in=input(data).line().csv();

string depthlabel=in;
string yearlabel=in;
string[] taxa=in;
group=in;
begin=in;
real[] depth;
int[] year;
real[][] percentage;

while(true) {
real d=in;
if(eof(in)) break;
depth.push(d);
year.push(in);
percentage.push(in);
}

percentage=transpose(percentage);
real depthmin=-min(depth);
real depthmax=-max(depth);

int n=percentage.length;

int final;
for(int taxon=0; taxon < n; ++taxon) {
real[] P=percentage[taxon];
if(max(P) < ignorebelow) continue;
final=taxon;
}

real angle=45;
real L=3cm;
pair Ldir=L*dir(angle);
real ymax=-infinity;
real margin=labelmargin();

real location=0;

for(int i=0; i < begin.length-1; ++i) end[i]=begin[i+1]-1;
end[begin.length-1]=n-1;

typedef void drawfcn(frame f);
drawfcn[] draw=new drawfcn[begin.length];

pair z0;

for(int taxon=0; taxon < n; ++taxon) {
real[] P=percentage[taxon];
real maxP=max(P);
if(maxP < ignorebelow) continue;
picture pic;
real x=1;
if(maxP < minpercent) x=minpercent/maxP;
if(maxP > 100) x=50/maxP;
scale(pic,Linear(true,x),Linear(-1));
filldraw(pic,(0,depthmin)--graph(pic,P,depth)--(0,depthmax)--cycle,
gray(0.9));
xaxis(pic,Bottom,LeftTicks("$%.3g$",beginlabel=false,0,2),above=true);
xaxis(pic,Top,above=true);

frame label;
label(label,rotate(angle)*TeXify(taxa[taxon]),(0,0),N);

pair z=point(pic,N);
pair v=max(label);
int taxon=taxon;
pic.add(new void(frame f, transform t) {
pair z1=t*z+v;
ymax=max(ymax,z1.y+margin);
});

for(int i=0; i < begin.length; ++i) {
pair z=point(pic,N);
pair v=max(label);
if(taxon == begin[i]) {
pic.add(new void(frame f, transform t) {
pair Z=t*z+v;
z0=Z;
pair w0=Z+Ldir;
});
} else if(taxon == end[i]) {
int i=i;
pair align=2N;
pair z0=z0;
pair z1=t*z+v;
pair w1=z1+Ldir;
draw[i]=new void(frame f) {
path g=z0--(z0.x+(ymax-z0.y)/Tan(angle),ymax)--
(z1.x+(ymax-z1.y)/Tan(angle),ymax)--z1;
draw(f,g);
label(f,group[i],point(g,1.5),align);
};
});
}
}

if(taxon == 0) yaxis(pic,depthlabel,Left,RightTicks(0,10),above=true);
if(taxon == final) yaxis(pic,Right,LeftTicks("%",0,10),above=true);

location += pic.userMax().x;
}

for(int i=0; i < draw.length; ++i)
draw[i](f);
});

for(int i=0; i < year.length; ++i)
if(year[i] != 0) label((string) year[i],(location,-depth[i]),E);

label("\%",(0.5*location,point(S).y),5*S);



Étiquettes : , ,

## Official Asymptote example – generalaxis

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 17 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph;
size(0,100);

path g=ellipse((0,0),1,2);

scale(true);

axis(Label("C",align=10W),g,LeftTicks(endlabel=false,8,end=false),
ticklocate(0,360,new real(real v) {
path h=(0,0)--max(abs(max(g)),abs(min(g)))*dir(v);
return intersect(g,h)[0];}));



Étiquettes : ,

## Official Asymptote example – generalaxis3

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 18 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph3;

size(0,100);

path3 g=yscale3(2)*unitcircle3;
currentprojection=perspective(10,10,10);

axis(Label("C",position=0,align=15X),g,InTicks(endlabel=false,8,end=false),
ticklocate(0,360,new real(real v) {
path3 h=O--max(abs(max(g)),abs(min(g)))*dir(90,v);
return intersect(g,h)[0];},
new triple(real t) {return cross(dir(g,t),Z);}));



Étiquettes : ,

## Official Asymptote example – leastsquares

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 22 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

size(400,200,IgnoreAspect);

import graph;
import stats;

file fin=input("leastsquares.dat").line();

real[][] a=fin.dimension(0,0);
a=transpose(a);

real[] t=a[0], rho=a[1];

// Read in parameters from the keyboard:
//real first=getreal("first");
//real step=getreal("step");
//real last=getreal("last");

real first=100;
real step=50;
real last=700;

// Remove negative or zero values of rho:
t=rho > 0 ? t : null;
rho=rho > 0 ? rho : null;

scale(Log(true),Linear(true));

int n=step > 0 ? ceil((last-first)/step) : 0;

real[] T,xi,dxi;

for(int i=0; i <= n; ++i) {
real first=first+i*step;
real[] logrho=(t >= first & t <= last) ? log(rho) : null;
real[] logt=(t >= first & t <= last) ? -log(t) : null;

if(logt.length < 2) break;

// Fit to the line logt=L.m*logrho+L.b:
linefit L=leastsquares(logt,logrho);

T.push(first);
xi.push(L.m);
dxi.push(L.dm);
}

draw(graph(T,xi),blue);
errorbars(T,xi,dxi,red);

crop();

ylimits(0);

xaxis("$T$",BottomTop,LeftTicks);
yaxis("$\xi$",LeftRight,RightTicks);



Étiquettes : , , ,

## Official Asymptote example – limit

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 1 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

size(200,200,IgnoreAspect);
import graph;

real L=1;
real epsilon=0.25;

real a(int n) {return L+1/n;}

for(int i=1; i < 20; ++i)
dot((i,a(i)));

real N=1/epsilon;

xaxis(Label("$n$",align=2S));
yaxis(Label("$a_n$",0.85));

xtick("$2$",2);
ytick("$\frac{3}{2}$",3/2);
ytick("$2$",2);

yequals(Label("$L$",0,up),L,extend=true,blue);
yequals(Label("$L+\epsilon$",1,NW),L+epsilon,extend=true,red+dashed);
yequals(Label("$L-\epsilon$",1,SW),L-epsilon,extend=true,red+dashed);

xequals(N,extend=true,darkgreen+dashed);
labelx(shift(0,-10)*"$N=\frac{1}{\epsilon}$",N,E,darkgreen);

label("$a_n=1+\frac{1}{n},\quad \epsilon=\frac{1}{4}$",point((0,1)),10S+E);



Étiquettes : , ,

## Official Asymptote example – lmfit1

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 6 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import lmfit;
import graph;

size(10cm, 7cm, IgnoreAspect);

real[] date = { 1790, 1800, 1810, 1820, 1830, 1840, 1850, 1860, 1870, 1880,
1890, 1900, 1910, 1920, 1930, 1940, 1950, 1960, 1970, 1980, 1990 };
real[] population = { 3.929, 5.308, 7.240, 9.638, 12.866, 17.069, 23.192, 31.443,
38.558, 50.156, 62.948, 75.996, 91.972, 105.711, 122.775, 131.669, 150.697,
179.323, 203.185, 226.546, 248.710 };

real t0 = 1776;

real P(real[] params, real t) {
real P0 = params[0];
real K = params[1];
real r = params[2];
return (K * P0) / (P0 + (K - P0) * exp(-r * (t - t0)));
}

real[] params = { 10, 500, 0.1 };

real res = lmfit.fit(date, population, P, params).norm;

write("P_0 = ", params[0]);
write("K = ", params[1]);
write("r = ", params[2]);
write("error = ", res);

real P(real t) {
return P(params, t);
}

draw(graph(date, population), blue);
draw(graph(P, t0, 2000), red);
xaxis("Year", BottomTop, LeftTicks);
yaxis("Population in millions", LeftRight, RightTicks);



Étiquettes : , , ,

## Official Asymptote example – log2graph

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 8 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph;
size(200,IgnoreAspect);

// Base-2 logarithmic scale on y-axis:

real log2(real x) {static real log2=log(2); return log(x)/log2;}
real pow2(real x) {return 2^x;}

scaleT yscale=scaleT(log2,pow2,logarithmic=true);
scale(Linear,yscale);

real f(real x) {return 1+x^2;}

draw(graph(f,-4,4));

yaxis("$y$",ymin=1,ymax=f(5),RightTicks(Label(Fill(white))),EndArrow);
xaxis("$x$",xmin=-5,xmax=5,LeftTicks,EndArrow);



Étiquettes : , ,

## Official Asymptote example – logdown

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 9 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph;
size(200,IgnoreAspect);

real log10Down(real x) {return -log10(x);}
real pow10Down(real x) {return pow10(-x);}

scaleT LogDown=scaleT(log10Down,pow10Down,logarithmic=true);
scale(Linear,LogDown);

draw(graph(exp,-5,5));

yaxis("$y$",RightTicks(Label(Fill(white)),DefaultLogFormat),BeginArrow);
xaxis("$x$",LeftTicks(NoZero),EndArrow);



Étiquettes : , ,

## Official Asymptote example – loggraph

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 10 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph;

size(200,200,IgnoreAspect);

real f(real t) {return 1/t;}

scale(Log,Log);

draw(graph(f,0.1,10));

//xlimits(1,10,Crop);
//ylimits(0.1,1,Crop);

dot(Label("(3,5)",align=S),Scale((3,5)));

xaxis("$x$",BottomTop,LeftTicks);
yaxis("$y$",LeftRight,RightTicks);



Étiquettes : , ,

## Official Asymptote example – loggrid

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 11 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph;
size(200,200,IgnoreAspect);

real f(real t) {return 1/t;}

scale(Log,Log);
draw(graph(f,0.1,10),red);
pen thin=linewidth(0.5*linewidth());
xaxis("$x$",BottomTop,LeftTicks(begin=false,end=false,extend=true,
ptick=thin));
yaxis("$y$",LeftRight,RightTicks(begin=false,end=false,extend=true,
ptick=thin));



Étiquettes : , , ,

## Official Asymptote example – logticks

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 15 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph;

size(300,175,IgnoreAspect);
scale(Log,Log);
draw(graph(identity,5,20));
xlimits(5,20);
ylimits(1,100);
xaxis("$M/M_\odot$",BottomTop,LeftTicks(DefaultFormat,
new real[] {6,10,12,14,16,18}));
yaxis("$\nu_{\rm upp}$ [Hz]",LeftRight,RightTicks(DefaultFormat));



Étiquettes : ,

## Official Asymptote example – markregular

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 21 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph;

size(10cm,0);

real xmin=-4,xmax=4;
real ymin=-2,ymax=10;

real f(real x) {return x^2;}

marker cross=marker(scale(4)*rotate(45)*cross(4),
markuniform(new pair(real t) {return Scale((t,f(t)));},
xmin,xmax,round(2*(xmax-xmin))),1bp+red);

draw(graph(f,xmin,xmax,n=400),linewidth(1bp),cross);

ylimits(-2.5,10,Crop);

xaxis(Label("$x$",position=EndPoint, align=NE),xmin=xmin,xmax=xmax,
Ticks(scale(.7)*Label(align=E),NoZero,begin=false,beginlabel=false,
end=false,endlabel=false,Step=1,step=.25,
Size=1mm, size=.5mm,pTick=black,ptick=gray),Arrow);

yaxis(Label("$y$",position=EndPoint, align=NE),ymin=ymin,ymax=ymax,
Ticks(scale(.7)*Label(),NoZero,begin=false,beginlabel=false,
end=false,endlabel=false,Step=1,step=.25,Size=1mm,size=.5mm,
pTick=black,ptick=gray),Arrow);



Étiquettes : , ,

## Official Asymptote example – monthaxis

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 23 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph;

size(400,150,IgnoreAspect);

real[] x=sequence(12);
real[] y=sin(2pi*x/12);

scale(false);

string[] month={"Jan","Feb","Mar","Apr","May","Jun",
"Jul","Aug","Sep","Oct","Nov","Dec"};

draw(graph(x,y),red,MarkFill[0]);

xaxis(BottomTop,LeftTicks(new string(real x) {
return month[round(x % 12)];}));
yaxis("$y$",LeftRight,RightTicks(4));



Étiquettes : , ,

## Official Asymptote example – scaledgraph

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 12 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph;

axiscoverage=0.9;
size(200,IgnoreAspect);

real[] x={-1e-11,1e-11};
real[] y={0,1e6};

real xscale=round(log10(max(x)));
real yscale=round(log10(max(y)))-1;

draw(graph(x*10^(-xscale),y*10^(-yscale)),red);

xaxis("$x/10^{"+(string) xscale+"}$",BottomTop,LeftTicks);
yaxis("$y/10^{"+(string) yscale+"}$",LeftRight,RightTicks(trailingzero));



Étiquettes : ,

## Official Asymptote example – secondaryaxis

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 13 h 57 min

 (Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */

import graph;

size(9cm,6cm,IgnoreAspect);
string data="secondaryaxis.csv";

file in=input(data).line().csv();

string[] titlelabel=in;
string[] columnlabel=in;

real[][] a=in.dimension(0,0);
a=transpose(a);
real[] t=a[0], susceptible=a[1], infectious=a[2], dead=a[3], larvae=a[4];
real[] susceptibleM=a[5], exposed=a[6],infectiousM=a[7];

scale(true);

draw(graph(t,susceptible,t >= 10 & t <= 15));
draw(graph(t,dead,t >= 10 & t <= 15),dashed);

xaxis("Time ($\tau$)",BottomTop,LeftTicks);
yaxis(Left,RightTicks);

picture secondary=secondaryY(new void(picture pic) {
scale(pic,Linear(true),Log(true));
draw(pic,graph(pic,t,infectious,t >= 10 & t <= 15),red);
yaxis(pic,Right,red,LeftTicks(begin=false,end=false));
});