# Plotting one period of f(x)=tan x with the vertical asymptotes

I would like to have the picture look like the hand drawing.Help would be greatly appreciated, thank you. • you can use metapost, geogebra or texgraph – touhami Mar 14 '15 at 18:04
• I should have specified that I am trying to do it using tikz-pgf – TuoTuo Mar 14 '15 at 18:43
• with geogebra or texgraph you can convert to tikz – touhami Mar 14 '15 at 18:50
• – touhami Mar 14 '15 at 19:02
• Please show us, what have you tried that isn't working? Most times, people don't like to answer questions that feel like "Do this thing for me", instead prefer to answer questions that are more like "I'm stuck with this small aspect, how can I accomplish it?" – darthbith Mar 14 '15 at 20:18

With pgfplots

\documentclass[border=4mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}

\begin{document}
\begin{tikzpicture}
\begin{axis}
[
ymin=-10,ymax=10,
xmin=-2,xmax=2,
%clip=false,
xtick=\empty,
ytick={-8,-6,...,8},
extra x ticks={-1.5708, 1.5708},
extra x tick labels={$-\frac{\pi}{2}$, $\frac{\pi}{2}$},
every extra x tick/.style={
xticklabel style={anchor=north west},
grid=major,
major grid style={thick,dashed,red}
},
axis lines = center,
xlabel=$x$,ylabel=$y$,
domain=-.5*pi:.5*pi,
samples=200,
]
\end{axis}
\end{tikzpicture}
\end{document} If you wish to give its chance to MetaPost, here is an example, included in a LuaLaTeX program, of what it can do with your problem:

\documentclass[12pt, border=1bp]{standalone}
\usepackage{amsmath, luamplib}
\mplibsetformat{metafun}
\mplibnumbersystem{double}
\mplibtextextlabel{enable}
\begin{document}
\begin{mplibcode}
vardef function(expr xmin, xmax, xstep)(text f_x) =
save x; x := xmin;
(x, f_x) forever:
hide(x := x + xstep)
exitif x > xmax;
.. (x, f_x)
endfor
if x - xstep < xmax: hide(x := xmax) .. (x, f_x) fi
enddef;
numeric u, xmin, xmax, Xmin, Xmax, xstep, ymin, ymax;
u = 1.5cm; Xmax = -Xmin = 2.25; Ymax = -Ymin = 4.75; xstep = 0.05; xmax = -xmin = 1.5;

beginfig(1);
draw function(xmin, xmax, xstep)(tan x) scaled u;
clip currentpicture to
((Xmin, Ymin) -- (Xmax, Ymin) -- (Xmax, Ymax) -- (Xmin, Ymax) -- cycle) scaled u;
draw u*(-pi/2, Ymin) -- u*(-pi/2, Ymax) dashed evenly;
draw u*(pi/2, Ymin) -- u*(pi/2, Ymax) dashed evenly;
drawarrow u*(Xmin, 0) -- u*(Xmax, 0);
drawarrow u*(0, Ymin) -- u*(0, Ymax);
label.bot("$x$", (Xmax*u, 0)); label.lft("$y$", (0, Ymax*u));
label.ulft("$O$", origin);
label.llft("$-\dfrac{\pi}{2}$", (-u*pi/2, 0));
label.llft("$\dfrac{\pi}{2}$", (u*pi/2, 0));
labeloffset := 6bp;
for i = -4 upto 4:
if i<>0:
draw (-3bp, i*u) -- (3bp, i*u); label.lft("$" & decimal i & "$", (0, i*u));
fi
endfor
endfig;
\end{mplibcode}
\end{document} • this does'nt answer the question. – touhami Mar 14 '15 at 20:19
• @touhami Strictly speaking, yes it does: ‘‘I would like to have the picture look like the hand drawing. Help would be greatly appreciated, thank you.’’ I know my solution does not use the OP's required package, but in general people here appreciate as well to see how the same drawing can be done with other graphical solutions. It can also help to improve the solutions given with the desired package, by emulation. What is really missing here is an example of coding given by the OP's, even rudimentary, showing how he had first tackled the problem… – Franck Pastor Mar 14 '15 at 20:46
• @touhami: As fpast said, it's generally accepted (and encouraged) to post answers that use different approaches or packages than what is requested by the asker (see meta.tex.stackexchange.com/questions/3408/…). In a way, answers aren't just for the benefit of the asker, but for the general community, and it's definitely instructive to see different approaches for achieving the same outcome. – Jake Mar 14 '15 at 21:19
• @fpast and jake (+1) you are right and the answer is welcom. I wanted to direct your attention to the question may have missed something (excuse my bad english) – touhami Mar 14 '15 at 21:57