Skip to content

Instantly share code, notes, and snippets.

@ngn999
Created January 12, 2013 06:39
Show Gist options
  • Save ngn999/4516458 to your computer and use it in GitHub Desktop.
Save ngn999/4516458 to your computer and use it in GitHub Desktop.
numeric xmax,ymax,xmin,ymin;
xmax := 4;
ymax := 2;
xmin := 0;
ymin := 0;

numeric ux,uy;
ux := 1cm;
uy := 1cm;

% draw axes
draw (xmin,0)*ux -- (xmax,0)*ux;
draw (0,ymin)*uy -- (0,ymax)*uy;

% draw ticks

for i=0 upto xmax:
   draw (i, -0.05)*ux -- (i,0.05)*ux;
   label.bot(decimal(i), (i,0)*ux);
endfor;

for i=0 upto ymax:
   draw (-0.05, i)*uy -- (0.05, i)*uy;
   label.lft(decimal(i), (0,i)*uy);
endfor;
labeloffset := 0.5cm;
label.bot(btex $x$ etex, (2,0)*ux);
label.lft(btex $y$ etex rotated 90, (0,1)*uy);

xinc := 0.1;
path func_path;
func_path := (xmin*ux, sqrt(xmin)*uy).. (0,0)
  for x=xmin+xinc step xinc until xmax:
     .. (x*ux, sqrt(x)*uy)
   endfor;

draw func_path withpen pencircle scaled 2bp;

labeloffset := 0;
label.bot(btex $y = \sqrt{x}$ etex, (2.5*ux, 1.2*uy));

paste to here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment