在 pgfplots 中,当绘制函数时,是-5:5
中的默认域。我想将其默认设置为xmin:xmax
。有没有办法做到这一点?换句话说,我希望能够写
\addplot {x^2};
代替
\addplot[domain=xmin:xmax] {x^2};
更具体地说,这是我所寻找的MWE(不起作用):
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{domain = min:max}
\begin{document}
\centering
\begin{tikzpicture}
\begin{axis}[xmin=-10, xmax=10, xlabel = $x$, ylabel = {$f(x) = x^2$}]
\addplot{x^2};
\end{axis}
\end{tikzpicture}
\end{document}
答案 0 :(得分:2)
\documentclass{article}
\usepackage{pgfplots}
%What you really need!
\newcommand\Min{-10}
\newcommand\Max{10}
\pgfplotsset{domain = \Min : \Max}
\begin{document}
\centering
\begin{tikzpicture}%x^2
\begin{axis}[xlabel = $x$, ylabel = {$f(x) = x^2$}]
\addplot{x^2};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}%-(x^2)
\begin{axis}[xlabel = $x$, ylabel = {$f(x) = -(x^2)$}]
\addplot{-x^2};
\end{axis}
\end{tikzpicture}
\end{document}