我希望图片看起来像手绘的。如能得到帮助我将非常感激,谢谢。
答案1
和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,
]
\addplot [red,thick] {tan(deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
如果您希望尝试一下 MetaPost,这里有一个包含在 LuaLaTeX 程序中的示例,可以说明它可以解决您的问题:
\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}