今回勉強になったのは,どちらかと言えばループを使ってグラフの目盛りを書くときの記述方法です.
今回作成したのは,次の$\tan x$のグラフです.
ソースコードは次の通りです.mathライブラリが必要です.
\begin{tikzpicture}[xscale=0.5,yscale=0.35]
\begin{scope}
\clip (-2.5*pi-0.5,-12) rectangle (2.5*pi+0.5,12);
\foreach \n/\ntext in
{-4/-2,-2/-,2/,4/2,-5/-\frac{5}{2},-3/-\frac{3}{2},-1/-\frac{1}{2},1/\frac{1}{2},3/\frac{3}{2},5/\frac{5}{2}}{
\tikzmath{
real \x1,\x2;
\x1=0.5*\n*pi;
\x2=(0.5*\n+1)*pi;
};
\draw[gray!40] (\x1,12)--(\x1,-12);
\pgfmathparse{mod(\n,2)==0?1:0}
\ifnum\pgfmathresult > 0
\node[fill=white,above left] at (\x1,0){$\ntext\pi$};
\else
\node[fill=white,below] at (\x1,0){$\ntext\pi$};
\ifnum\n < 5
\draw[thick] plot[id=tangent\n,prefix=figures/tikz/plots/,raw gnuplot]
function{set samples 50;plot [\x1+0.08:\x2-0.08] tan(x)} ;
\fi
\fi
}
\draw[gray!40] (2.5*pi,12)--(2.5*pi,-12);
\node[below right] at (0,0){$0$};
\foreach \n in {-10, -5, 5, 10}{
\draw (-0.1,\n)--(0.1,\n);
\node[left] at (0,\n){$\n$};
}
\end{scope}
\draw[->] (-2.5*pi-0.2,0)--(2.5*pi+0.5,0) node[right] {$x$};
\draw[->] (0,-12)--(0,12) node[left] {$y$};
\end{tikzpicture}