Καλημέρα!
I 'm trying to draw the curve y=tan(x).
- When I draw the curve at the domain (-π/2,π/2) everything is OK (see the 1st code and the image).
- When I draw the curve at other domains (e.g.
(π/2,3π/2)) something goes bad (see the 2nd code and the image.
What is happening? How can I fix it?
Domain=(-π/2,π/2)
\documentclass{article}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}[>=latex]
\begin{axis}[
axis x line=center,
axis y line=center,
xlabel={$x$},
ylabel={$y$},
xlabel style={below right},
ylabel style={above left},
xmin=-8.5,
xmax=8.5,
ymin=-8,
ymax=8,
xtick={-3*(pi/2),-pi,-pi/2,0,pi/2,pi,3*pi/2},
xticklabels={$-\frac{3\pi}{2}$,$-\pi$,$-\frac{\pi}{2}$,$0$,$\frac{\pi}{2}$,$\pi$,$\frac{3\pi}{2}$}]
\addplot [domain=-pi/2:pi/2,ultra thick,smooth] {tan(deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}
Domain=(-π/2,π/2)
\documentclass{article}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}[>=latex]
\begin{axis}[
axis x line=center,
axis y line=center,
xlabel={$x$},
ylabel={$y$},
xlabel style={below right},
ylabel style={above left},
xmin=-8.5,
xmax=8.5,
ymin=-8,
ymax=8,
xtick={-3*(pi/2),-pi,-pi/2,0,pi/2,pi,3*pi/2},
xticklabels={$-\frac{3\pi}{2}$,$-\pi$,$-\frac{\pi}{2}$,$0$,$\frac{\pi}{2}$,$\pi$,$\frac{3\pi}{2}$}]
\addplot [domain=pi/2:3*pi/2,ultra thick,smooth] {tan(deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}
Ευχαριστώ εκ των προτέρων!




samples=option. Now as the tangent function has vertical asymptotes at 90° (and then every 180° of course), this will yield a very large value shortly before 90° and a very small (very negative) value shortly after. As a consequence, this gives an almost vertical line as an artifact. To fix it, you will need to draw the different parts separately. – Philipp Imhof Dec 17 '18 at 09:11