2

Consider the following MWE:

\documentclass[tikz]{standalone}

\usepackage{tikz,pgfplots}
\pgfplotsset{%
  compat=newest,
  colormap={orangeyellow}{color=(orange) color=(yellow)}
}

\begin{document}
   \begin{tikzpicture}
      \begin{axis}[
         domain=0:180,
         y domain=0:360,
         z buffer=sort,
         colormap/orangeyellow]
         \addplot3[surf] ({sin(x)*cos(y)},{sin(x)*sin(y)},{cos(x)});
      \end{axis}      
   \end{tikzpicture}
\end{document}

I get the error

Package pgfkeys Error: I do not know the key '/tikz/colormap/orangeyellow' and I am going to ignore it. Perhaps you misspelled it.

However, the output is rendered correctly, because (as I suppose) pgfplots automatically uses the last colormap that was defined. This kind of solves the problem for now, but if I were to define to colormaps, I would still need a real solution.

Also (and mainly), I do not understand why pgfkeys thinks I am referring to /tikz/colormap instead of /pgfplots/colormap. It clearly does not do this for the predefined colormap/redyellow, nor for any other of the keys I pass to the axis environment.

3

The correct key to use is colormap name=orangeyellow. See e.g. this related answer for more options.

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{colormaps}%
\pgfplotsset{%
  compat=newest,
  colormap={orangeyellow}{
  color=(orange) color=(yellow)
  },
}

\begin{document}
   \begin{tikzpicture}
      \begin{axis}[
         domain=0:180,
         y domain=0:360,
         z buffer=sort,
         colormap name=orangeyellow]
         \addplot3[surf] ({sin(x)*cos(y)},{sin(x)*sin(y)},{cos(x)});
      \end{axis}      
   \end{tikzpicture}
\end{document}

enter image description here

If you want to use your syntax, you need to define a style of that name.

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{colormaps}%
\pgfplotsset{%
  compat=newest,
  colormap={orangeyellow}{
  color=(orange) color=(yellow)
  },
  colormap/orangeyellow/.style={
        colormap name=orangeyellow,
    },
}

\begin{document}
   \begin{tikzpicture}
      \begin{axis}[
         domain=0:180,
         y domain=0:360,
         z buffer=sort,
         colormap/orangeyellow]
         \addplot3[surf] ({sin(x)*cos(y)},{sin(x)*sin(y)},{cos(x)});
      \end{axis}      
   \end{tikzpicture}
\end{document}
  • 1
    Thank you very much for that answer and also for the link to the related question which I unfortunately did not find before asking mine... – Philipp Imhof Jul 11 at 19:16
  • @PhilippImhof You're welcome! – user121799 Jul 11 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.