# Problem with Asymptote axis functions doc-s and samples

I am trying to learn Asymptote as I use it. I was trying to reproduce the image shown below, via Asymptote's axis (grid) functions (or any other package, such as graph.asy). I wasn't able to understand the corresponding portion of the manual and I wasn't able to find anyplace in the Charles Staat tutorial on point. Also, I wasn't able to find any samples that were on point.

I finally created the graph manually, with the following inline code. How could I have duplicated the graph with pre-existing Asymptote functions?

\begin{asy}
size(3.3cm,3.3cm);
defaultpen(fontsize(9pt));

for (int i = -12; i <= 12; ++i) {
draw((i/2,-2pi) -- (i/2, 2pi), palegrey);
if (i %2 == 0) { draw((i/2,-2pi) -- (i/2, 2pi), grey); }
if (i %4 == 0) { label(string(i/2,2), (i/2, -2pi), S, fontsize(8pt)); }
}

for (int i = -2; i <= 2; ++i) {
draw((-2pi,i*pi) -- (2pi,i*pi), grey);
if (i == 0)
{ label("$0$", (-2pi, 0), W, fontsize(8pt)); }
else
{ label(string(i,2) + "pi", (-2pi, i*pi), W, fontsize(8pt)); }
}
\end{asy} Here I propose two solutions. In the first one I define the function which gives the label string (for y axis to have pi and also for x axis to have even number).

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

xlimits( -6, 6);
ylimits( -2pi, 2pi);

string ylab(real x)
{
string s;
s="$"+string(round(x/pi))+"\pi$";
if (abs(x)<epsilon) {s="0";}
if (round(x/pi)==1) {s="$\pi$";}
if (round(x/pi)==-1) {s="$-\pi$";}
return s;
}
string xlab(real x)
{
string s;
s=string(x);
if (round(x)%2==1) {s="";}
return s;
}
yaxis( LeftRight(), RightTicks(new string(real x) { return ylab(x);},Step=pi,pTick=black, ptick=lightgrey, extend=true));
xaxis(  BottomTop(), Ticks(new string (real x) {return xlab(x);}, Step=1, step=.5, pTick=black, ptick=lightgrey, extend=true));


In the second solution I use base_pi.asy and graph_pi.asy unofficial packages. It gives grid routine and a labelfrac routine to have a fraction kind label. You can find its here http://www.piprime.fr/asymptote/unofficial-asymptote-packages/

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

xlimits( -6, 6);
ylimits( -2pi, 2pi);

grid(xStep=1, xstep=1/2,
yStep=pi, ystep=pi,
pTick=.7bp+black,
ptick=.7bp+.7white,
above=false
);

yaxis( LeftRight, RightTicks(labelfrac(
factor=pi,
symbol="\pi",
symbolin=true,
zero=true),
Step=pi,pTick=black, ptick=lightgrey));
xaxis( BottomTop, LeftTicks(Label("$%.2f$"), Step=2, step=1/2, ptick=lightgrey));


and the result • Wow. Thanks, this will be interesting research. – user2661923 Apr 4 '20 at 22:27