我有一条抛物线的图。它的顶点位置(2,16)
严重错误。
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[height=3in,width=3in, clip=false,
xmin=-4,xmax=8,
ymin=-12,ymax=22,
restrict y to domain=-12:22,
ticklabel style={font=\tiny,fill=white},
xtick={\empty},ytick={\empty},
xtick={-2},ytick={16},
xticklabel style={font=\tiny, fill=white, below right},
xticklabels={\makebox[0pt][r]{$-$}{2}},
extra x ticks={6},
extra x tick style={xticklabel style={below left}},
extra x tick labels={6},
enlargelimits={abs=1cm},
axis lines=middle,
axis line style={latex-latex},
xlabel=$x$,ylabel=$y$,
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=501, domain=-3:7, blue] {-x^2 + 4*x + 12} node[anchor=west, pos=1, font=\footnotesize]{$y = -x^{2} + 4x + 12$};
\addplot [dashed, latex-latex, domain=-10:20] (2,x) node [pos=0.10, anchor=north, font=\tiny, sloped]{$x=2$};
\draw[fill] (2,16) circle [radius=1.5pt];
\node[anchor=225, inner sep=0, font=\footnotesize] at ($(2,16) +(45:0.15)$){$(2,16)$};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
我不知道到底发生了什么,但我也不太明白你为什么要费那么大劲去加这样的标签。为什么不直接
\draw[fill] (2,16) circle [radius=1.5pt] node[above right,font=\footnotesize]{$(2,16)$};
pgfplots
默认情况下会重新缩放所有数据,这似乎会与您尝试的坐标计算发生冲突。disabledatascaling
但是,如果您添加到轴选项中,您的代码将按预期运行。
下面是完整的示例。我将所有设置添加到样式中只是为了缩短代码并突出差异。
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usetikzlibrary{calc}
\pgfplotsset{adelyndefaults/.style={
height=3in,width=3in, clip=false,
xmin=-4,xmax=8,
ymin=-12,ymax=22,
restrict y to domain=-12:22,
ticklabel style={font=\tiny,fill=white},
xtick={\empty},ytick={\empty},
xtick={-2},ytick={16},
xticklabel style={font=\tiny, fill=white, below right},
xticklabels={\makebox[0pt][r]{$-$}{2}},
extra x ticks={6},
extra x tick style={xticklabel style={below left}},
extra x tick labels={6},
enlargelimits={abs=1cm},
axis lines=middle,
axis line style={latex-latex},
xlabel=$x$,ylabel=$y$,
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
adelyndefaults,
]
\addplot[samples=21, domain=-3:7, blue] {-x^2 + 4*x + 12} node[anchor=west, pos=1, font=\footnotesize]{$y = -x^{2} + 4x + 12$};
\addplot [dashed, latex-latex, domain=-10:20] (2,x) node [pos=0.10, anchor=north, font=\tiny, sloped]{$x=2$};
\draw[fill] (2,16) circle [radius=1.5pt] node[above right,font=\footnotesize]{$(2,16)$};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[
adelyndefaults,
disabledatascaling
]
\addplot[samples=21, domain=-3:7, blue] {-x^2 + 4*x + 12} node[anchor=west, pos=1, font=\footnotesize]{$y = -x^{2} + 4x + 12$};
\addplot [dashed, latex-latex, domain=-10:20] (2,x) node [pos=0.10, anchor=north, font=\tiny, sloped]{$x=2$};
\node[anchor=225, inner sep=0,font=\footnotesize] at ($(axis cs:2,16) +(45:0.15)$){$(2,16)$};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
PSTricks 解决方案:
\documentclass{article}
\usepackage{pst-plot}
\begin{document}
\psset{yunit = 0.5}
\begin{pspicture}(-2.5,-2)(6.85,17.8)
\psaxes[ticks = none, labels = none]{->}(0,0)(-2.5,-2)(6.5,17)[$x$,0][$y$,90]
\psplot[algebraic, linecolor = blue]{-2.2}{6.2}{-x^2+4*x+12}
\uput[300](-2,0){$-2$}
\uput[240](6,0){$6$}
\psline[linestyle = dashed](0,16)(2,16)(2,0)
\uput[270](2,0){$2$}
\uput[180](0,16){$16$}
\psdot(2,16)
\uput[90](2,16){$(2,16)$}
\rput(3.7,7){\textcolor{blue}{$-x^{2} + 4x + 12$}}
\end{pspicture}
\end{document}