0

I'm trying to draw a room illuminated by a light, so I reached this far, but I don't know what are my options for the colormap

\documentclass[border=0.2cm]{standalone}
 
\usepackage{pgfplots}
\usepgfplotslibrary{colormaps}
 
\pgfplotsset{compat = newest}
 
\begin{document}

\begin{tikzpicture}[scale=0.25]
\begin{axis}[
    axis equal image,
    grid = both,
    minor tick num = 2,
    xlabel = {$x$},
    ylabel = {$y$},
    zlabel = {$z$},
    major grid style = {draw = lightgray},
    minor grid style = {draw = lightgray!25},
    legend cell align={left},
    ymin = -1, ymax = 1,
    xmin = -1, xmax = 1,
    scale = 3,
    zmin = 0, zmax = 1.1,
    z buffer = sort,
]
 
% top of the cone
\addplot3[
    surf,
    shader = interp,
    samples = 50,
    samples y = 5,
    domain = 0:2*pi,
    domain y = 0:1,
    opacity = 0.65,
    colormap/yellowwhite,
]
(
    {(cos(deg(x)))*(1-y)},
    {(sin(deg(x)))*(1-y)},
    {y}
);
 

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

1 Answer 1

3

It's all explained in the manual:

Chapter 4: The Reference
Markers, Linestyles, (Background) Colors and Colormaps
Color Maps

This is on page 195 of the manual labelled “Revision 1.18.1 (2021/05/15)”. For instance, you can define a color map and give it a name:

\pgfplotsset{
  colormap={my colormap}{rgb=(0,0,1) color=(black) rgb255=(238,140,238)},
}

then use it with colormap name=my colormap.

\documentclass[border=0.2cm]{standalone}
\usepackage{pgfplots}

\pgfplotsset{
  compat=1.18,
  colormap={my colormap}{rgb=(0,0,1) color=(black) rgb255=(238,140,238)},
}

\begin{document}

\begin{tikzpicture}[scale=0.25]
\begin{axis}[
    axis equal image,
    grid = both,
    minor tick num = 2,
    xlabel = {$x$},
    ylabel = {$y$},
    zlabel = {$z$},
    major grid style = {draw = lightgray},
    minor grid style = {draw = lightgray!25},
    legend cell align={left},
    ymin = -1, ymax = 1,
    xmin = -1, xmax = 1,
    scale = 3,
    zmin = 0, zmax = 1.1,
    z buffer = sort,
]

\addplot3[
    surf,
    shader = interp,
    samples = 50,
    samples y = 5,
    domain = 0:2*pi,
    domain y = 0:1,
    opacity = 0.65,
    colormap name=my colormap,
  ]
  (
      {(cos(deg(x)))*(1-y)},
      {(sin(deg(x)))*(1-y)},
      {y}
  );
\end{axis}

\end{tikzpicture}
\end{document}

enter image description here

What you want may look like this:

\pgfplotsset{
  colormap={yellowwhite}{rgb=(1,1,0) rgb=(1,1,0.8) rgb=(1,1,1)},
}

...

\addplot3[..., colormap name=yellowwhite] (...); ...

enter image description here

The predefined color maps, when \usepgfplotslibrary{colormaps} is not used, are viridis and hot (the default). If you load the pgfplots colormaps library, many more color maps are readily available: autumn, bled, bright, bone, cold, copper, copper2, earth, etc.: see the manual under Related LibrariesColormaps (page 430 in my version).

Example with the hsv2 colormap. Note the \pgfplotsset{colormap/hsv2} in order to load it; then it can be used with colormap name=hsv2 (well, you could use colormap/hsv2 in the \addplot3 optional argument without doing the \pgfplotsset{colormap/hsv2} at all, but this would be less efficient in case you use this colormap several times in the same document).

\documentclass[border=0.2cm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{colormaps}
\pgfplotsset{compat=1.18}

\pgfplotsset{colormap/hsv2} % <-------- this loads the 'hsv2' color map

\begin{document}

\begin{tikzpicture}[scale=0.25]
\begin{axis}[
    axis equal image,
    grid = both,
    minor tick num = 2,
    xlabel = {$x$},
    ylabel = {$y$},
    zlabel = {$z$},
    major grid style = {draw = lightgray},
    minor grid style = {draw = lightgray!25},
    legend cell align={left},
    ymin = -1, ymax = 1,
    xmin = -1, xmax = 1,
    scale = 3,
    zmin = 0, zmax = 1.1,
    z buffer = sort,
]

\addplot3[
    surf,
    shader = interp,
    samples = 50,
    samples y = 5,
    domain = 0:2*pi,
    domain y = 0:1,
    opacity = 0.65,
    % or 'colormap/hsv2', but this is less efficient
    colormap name=hsv2,
  ]
  (
      {(cos(deg(x)))*(1-y)},
      {(sin(deg(x)))*(1-y)},
      {y}
  );

\end{axis}

\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .