删除默认的切线渐近线并添加虚线(tikz)

删除默认的切线渐近线并添加虚线(tikz)

我想我知道如何添加虚线渐近线\draw [dashed] (1st pt) -- (2nd pt),但在此之前我必须删除默认渐近线。也许一种方法是在渐近线的邻域中截断域,以便得到一个由(在本例中)5 个较小集合组成的域,但我不知道该怎么做。也许还有更简单的解决方案。

在此处输入图片描述

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{geometry}
\geometry{
   showframe, % mostra l'area di lavoro
   a4paper,top=2cm,bottom=3cm,left=2.5cm,right=3cm,% per regolare i bordi a piacimento
   heightrounded,bindingoffset=5mm}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
ymin=-6,ymax=6,
xmin=-6,xmax=6,
xtick=\empty,
ytick=\empty,
extra x ticks={-4.71,-3.14,-1.57,0,1.57,3.14,4.71},
extra x tick labels={$-\frac{3\pi}{2}$,$-\pi$,$-\frac{\pi}{2}$,0,$\frac{\pi}{2}$,$\pi$,$\frac{3\pi}{2}$},
axis lines=center,
xlabel={$x$},
ylabel={$y$},
domain=-1.8*pi:1.8*pi, ]
\addplot [samples=200] {tan(deg(x))};
\end{axis}
\end{tikzpicture}

\end{document}

答案1

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymin=-6,ymax=6,
xmin=-6,xmax=6,
xtick=\empty,
ytick=\empty,
extra x ticks={-4.71,-3.14159,-1.5708,0,1.57,3.14,4.71},
extra x tick labels={$-\frac{3\pi}{2}$,$-\pi$,$-\frac{\pi}{2}$,0,$\frac{\pi}{2}$,$\pi$,$\frac{3\pi}{2}$},
axis lines=center,
xlabel={$x$},
ylabel={$y$},
domain=-1.8*pi:1.8*pi,
samples=1000]
\addplot [dashed] {tan(deg(x))};
\addplot [restrict y to domain=-10:10,line width=1pt] {tan(deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容