我正在尝试使用 PGFPlots 绘制两个方程。它们是-(x-7)^2+12
和(x-6)^2-2
。但是,生成的图形拒绝绘制 x=5 以外的图形。我查看了用于配置绘图的代码,似乎没有任何东西导致此问题。
最小工作示例:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = middle,
xmin = 0, xmax = 10,
xtick = {0,2,...,10},
extra y ticks = 0,
ymin = -5, ymax = 15,
ytick = {-5,0,...,15},
samples = 100,
]
\addplot[color=red]{-(x-7)^2+12};
\addplot[color=blue]{(x-6)^2-2};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
PGFPlotsdomain={-5:5}
默认设置将绘图限制为 -5 ≤X≤5.但你可以轻松地改变这一点:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = middle,
xmin = 0, xmax = 10,
xtick = {0,2,...,10},
extra y ticks = 0,
ymin = -5, ymax = 15,
ytick = {-5,0,...,15},
samples = 100,
domain = {0:10}
]
\addplot[color=red]{-(x-7)^2+12};
\addplot[color=blue]{(x-6)^2-2};
\end{axis}
\end{tikzpicture}
\end{document}
(您也可以将此选项与\addplot
命令一起使用。)