5

I'm using domain=min:max within pgfplots, but unless I provide the same limits to gnuplot explicitly, they are ignored and gnuplot proceeds with plotting in the range [-10,10] (I assume that is the default range). Is there any way I can have gnuplot inherit the domain limits? If not, is there a way to pass them to gnuplot using\pgfkeysvalueof{<whatever>}?

MWE:

\documentclass{article}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=newest}

\begin{document} \begin{tikzpicture} \begin{axis}[ domain=-2:2,]

\addplot3[raw gnuplot,surf,samples=20,]
  gnuplot[surf,] {%
    splot [-2:2] [-2:2] (1-x)^2 + 100*(y-x^2)^2
    % splot (1-x)^2 + 100*(y-x^2)^2 % This defaults in the range [-10,10].
  };

\end{axis} \end{tikzpicture}% \end{document}

sudosensei
  • 4,072

1 Answers1

5

raw gnuplot disables the use of samples and domain.

You basically found the solution yourself: You can access the domain setting using \pgfkeysvalueof{/pgfplots/domain}:

\documentclass{article}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    domain=-2:2]

    \addplot3[raw gnuplot, surf,samples=20,]
      gnuplot{%
        splot [\pgfkeysvalueof{/pgfplots/domain}] [\pgfkeysvalueof{/pgfplots/domain}] (1-x)^2 + 100*(y-x^2)^2
      };
  \end{axis}
\end{tikzpicture}%
\end{document}
Jake
  • 232,450
  • Great. I just didn't think it would be that easy. I thought it would break something. In a similar vein, do you know how I would set the domain when I'm using gnuplot like this: \addplot3[contour gnuplot={number{20},labels=true},samples=40,thick,] {x^2+y^2};? – sudosensei Sep 16 '13 at 16:04
  • 1
    @sudosensei: In that case, you can use the normal domain key: \addplot3[domain=-5:5, contour gnuplot={number={20},labels=true},samples=10,thick] {x^2+y^2};. You only need that \pgfkeysvalueof approach if you're using raw gnuplot. – Jake Sep 16 '13 at 16:08
  • Excellent. Good to know that raw gnuplot ignores the values. Everything makes much more sense now. Thank you so much. – sudosensei Sep 16 '13 at 16:10