pgfkeys error with pgfplots/colormap

by Philipp Imhof   Last Updated July 11, 2019 19:23 PM

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.



Answers 1


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}
marmot
marmot
July 11, 2019 19:11 PM

Related Questions


Updated February 04, 2017 14:09 PM

Updated April 02, 2018 10:23 AM

Updated February 05, 2019 16:23 PM

Updated May 15, 2015 00:10 AM

Updated May 04, 2018 16:23 PM