Reputation: 76
In pgfplots, when plotting a function, the default domain in -5:5
. I would like to set this to be xmin:xmax
by default. Is there a way to do this? In other words, I would like to be able to write
\addplot {x^2};
instead of
\addplot[domain=xmin:xmax] {x^2};
To be more specific, here is a MWE of what I look for (and does not work):
\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}
Upvotes: 3
Views: 3395
Reputation: 973
\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}
Upvotes: 2