3

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}
4

1 回答 1

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}

输出

于 2018-08-13T03:26:44.553 回答