Asymptote - How do I set the size of my diagram in order to prevent my function from overflowing?

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:

\begin{asy}
// rnoanvrno
unitsize(1cm);
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;

// 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);
draw(g);

\end{asy}


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.

• Welcome to TeX.SE! 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

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

// 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);
draw(Label("$e^x$",Relative(.8),LeftSide),g,red);
draw(Label("$x$",EndPoint,S),(xmin-.3,0)--(xmax+.5,0),Arrow(TeXHead));
draw(Label("$y$",EndPoint,W),(0,-1)--(0,2+exp(xmax)),Arrow(TeXHead));
label("$1$",(0,1),NW);
label("O",(0,0),SW);


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