Simple question here. I'm fairly new to Asymptote for LaTex diagrams and would like to plot the exponential function.

The problem is that it takes big values for small values of x, hence increases really fast. Here's my code:

// rnoanvrno        
size(5cm, 5cm);
import graph;

// Declare variables
real xmin = 0;
real xmax = 3;
real ymin = 0;
real ymax = 3;
pair origin = (xmin, ymin);
pair xline = (xmax, ymin);
pair yline = (xmin, ymax);

// Define the paths for the graph
path xaxis = origin -- xline;
path yaxis = origin -- yline;
arrowbar arrow = Arrow(TeXHead);

// Draw the axes and titles
draw(xaxis, arrow);
draw(yaxis, arrow);
label("t", xline, SE);
label("x(t)", yline, NW);

// Declare the function to plot
real f(real x) {
return exp(x);

// Display it 
path g = graph(f, xmin, xmax, n=200);


exp(x) graphed

As you can see, this is quite inconvenient. How should I fix this ? I was thinking of setting size(5cm, 5cm) but has not effect at all. Is there a way to crop the function or stop displaying values after a certain threshold ?

Another idea I had was to plot it in terms of y instead of x, replacing path g = graph(f, xmin, xmax, n=200); the xmin, xmax values by ymin, ymax, provided that it is possible.

Thanks in advance

  • Welcome to TeX.SE!
    – Mensch
    Commented Oct 6, 2021 at 14:31
  • // rnoanvrno size(5cm,false); import graph; // Declare variables real xmin = 0; real xmax = 3; real ymin = 0; real ymax = 3; // Display it path g = graph(exp, xmin, xmax, n=200); draw(Label("$e^x$",Relative(.8),LeftSide),g); yaxis("$x(t)$",ymin,ymax=exp(ymax), RightTicks(Label(fontsize(8pt)), end=false), Arrow(TeXHead)); xaxis("$t$",xmin,xmax,LeftTicks,Arrow(TeXHead)); write(exp(ymax)); Commented Oct 6, 2021 at 16:02
  • Consider accepting and uovoting the provided answer if it solves your problem. Commented Oct 10, 2021 at 4:42

1 Answer 1


It is a naive way (I guess beginners like this!) of drawing using plain Asymptote command as follows.

enter image description here

// http://asymptote.ualberta.ca/
unitsize(1cm,3mm); // scaling x and y
size(6cm);         // auto-scaling the whole figure
import graph;  
real xmin=-1,xmax=2;
path g=graph(exp,xmin,xmax);

There are lot of sample code for 2D graph at the gallery of Asymptote.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .