移動刻度線

移動刻度線

我想將 x 軸上的刻度線 -2 從其通常位置移動到 x 軸上方。我畫了一條從 (-2,0) 到 (-2,-4) 的虛線,但我不希望它畫在這個刻度線上。

\documentclass{amsart}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}


\begin{tikzpicture}
\begin{axis}[width=4in,axis equal image,
    axis lines=middle,
    xmin=-16,xmax=16,samples=201,
    xlabel=$x$,ylabel=$y$,
    ymin=-12,ymax=12,
    restrict y to domain=-12:12,
    enlargelimits={abs=1cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={-2},ytick={\empty},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot [latex-latex,domain=-10:14] {x - 2} node [pos=0.9, anchor=north west, font=\footnotesize] {$y=\frac{x^{2}-4}{x+2}$};
\draw [thin,dashed] (-2,0) -- (-2,-4);
\draw [fill=white] (-2,-4) circle [radius=1.5pt] node[left,font=\tiny]{$(-2, \, -4)$};
\end{axis}
\end{tikzpicture}

\end{document}

答案1

一種簡單的方法來放置單身的刻度標籤是透過\node

在此輸入影像描述

筆記:

  • 如果造訪環境內的座標,axis您應該指定axis cs座標系。

代碼:

\documentclass{amsart}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}


\begin{tikzpicture}
\begin{axis}[width=4in,axis equal image,
    axis lines=middle,
    xmin=-16,xmax=16,samples=201,
    xlabel=$x$,ylabel=$y$,
    ymin=-12,ymax=12,
    restrict y to domain=-12:12,
    enlargelimits={abs=1cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},%xtick={-2},
    ytick={\empty},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot [latex-latex,domain=-10:14] {x - 2} node [pos=0.9, anchor=north west, font=\footnotesize] {$y=\frac{x^{2}-4}{x+2}$};
\draw [thin,dashed] (axis cs: -2,-4) -- (axis cs: -2,0) node [above] {\tiny$-2$};
\draw [fill=white] (axis cs: -2,-4) circle [radius=1.5pt] node[left,font=\tiny]{$(-2, \, -4)$};
\end{axis}
\end{tikzpicture}

\end{document}

答案2

另一種方法,使用xticklabel shift密鑰:

\documentclass{amsart}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}


\begin{tikzpicture}
\begin{axis}[width=4in,axis equal image,
    axis lines=middle,
    xmin=-16,xmax=16,samples=201,
    xlabel=$x$,ylabel=$y$,
    ymin=-12,ymax=12,
    restrict y to domain=-12:12,
    enlargelimits={abs=1cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={-2},ytick={\empty},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west},
    xticklabel shift=-16pt,
]
\addplot [latex-latex,domain=-10:14] {x - 2} node [pos=0.9, anchor=north west, font=\footnotesize] {$y=\frac{x^{2}-4}{x+2}$};
\draw [thin,dashed] (-2,0) -- (-2,-4);
\draw [fill=white] (-2,-4) circle [radius=1.5pt] node[left,font=\tiny]{$(-2, \, -4)$};
\end{axis}
\end{tikzpicture}

\end{document}

在此輸入影像描述

請注意,這將發生變化全部x 如果您的實際用例有多個,請勾選標籤。

答案3

這個例子並沒有完全回答問題,而是為問題添加色彩的一個例子:

\documentclass{amsart}

\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{color}

\pgfplotsset{compat=1.11}

\begin{document}


\begin{tikzpicture}
\begin{axis}[width=4in,axis equal image,
    axis lines=middle,
    xmin=-16,xmax=16,samples=201,
    xlabel=${\color{blue}{x}}$,
    ylabel=${\color{blue}{y}}$,
    ymin=-12,ymax=12,
    restrict y to domain=-12:12,
    enlargelimits={abs=1cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},%xtick={-2},
    ytick={\empty},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot [purple, latex-latex,domain=-10:14] {x - 2} node [pos=0.9, anchor=north west, font=\footnotesize] 
{\color{violet}{$y=\frac{x^{2}-4}{x+2}$}};
\draw [blue,thin,dashed] (axis cs: -2,-4) -- (axis cs: -2,0.2) node [above] {\tiny$-2$};
\draw [green, thin, dashed] (axis cs: -2, -4) -- (axis cs: 0.2, -4) node [right] {\tiny$-4$};
\draw [red, fill=white] (axis cs: -2,-4) circle [radius=1.5pt] node[left,font=\tiny]{$(-2, \, -4)$};
\end{axis}
\end{tikzpicture}

\end{document}

相關內容