# PGFPlots: Drawing a sphere and mapping CIELab color space

I'm currently working on a figure including a sphere with PGFPlots, based on this (hopefully usable) Solution, though with a different (kind of exotic) color mapping.

My idea: Applying a mapping and cross-sectioning without lines like the CIELab Color Space, but I am lacking the experience with color mapping (and \addplot3) in PGFPlots to solve this issue.

Does anyone have a good guide or tips for color mapping in PGFPlots / TikZ which might help solving this?

I already searched through the PGFPlots Manual (page 192), with

colormap={<name>}{<color specification>}


stating that one can use for example

\pgfplotsset{
colormap={mygreen}{rgb255(0cm)=(0,0,0); rgb255(1cm)=(0,255,0)}
}


to define a color value for a certain axis / at a certain axis value (I guess?).

The special problem now is to get a mapping which is, like in CIELab, axis specific (green / red, blue / yellow, black / white); I just, unfortunately, have no idea how to perform this mapping (and if this is possible at all).

Any ideas out there? :)

Thanks a lot!

Best,

Marius.

• Hey, oops - sorry! Well, the CIELab Color Space describes a sphere in 3D space, having different colors on the x-axis (running from pure green, which would be for example 0,255,0 in RGB, to pure red), y-axis (pure blue to pure yellow) and z-axis (pure white to pure black). As far as I understood, PGFPlots can only map a color spectrum to one axis / axis values (in \addplot3 being the z-axis, I think?) and not to three axes, which I would require and which seems to be a little bit more complex; that's at least (apparently) what pops out from the compiling process when using the Commented Oct 5, 2019 at 21:10
• solution I found before. If you need an image of the color space, I added a link to a figure in the original post. ;) Commented Oct 5, 2019 at 21:10

This is to answer the question whether or not one can have multidimensional color maps. The answer is yes. There is a specific example on p. 149 of the pgfplots manual, which I am combining with the example you link to. You can let the RGB value of the color depend on the coordinates. I chose red=y,green=x,blue=z since I was not really able to parse your description.

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{patchplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis equal,
width=10cm,
height=10cm,
axis lines = center,
xlabel = {$x$},
ylabel = {$y$},
zlabel = {$z$},
ticks=none,
enlargelimits=0.3,
z buffer=sort,
view/h=45,
scale uniformly strategy=units only]
% this example burns colors if opacity
% is active in the document.
patch type=bilinear,
mesh/color input=explicit mathparse,
variable = \u,
variable y = \v,
domain = 0:360,
y domain = 0:180,
point meta={symbolic={0.5+0.5*y, % R
0.5+0.5*x, % G
0.5+0.5*z%B
} },
] ({cos(u)*sin(v)}, {sin(u)*sin(v)}, {cos(v)});
\draw (1,0,0) -- (1.5,0,0) (0,-1,0)   -- (0,-1.5,0) (0,0,1)   -- (0,0,1.5);
\end{axis}
\end{tikzpicture}
\end{document}


In order to see the y dependence, let's change the view

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{patchplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis equal,
width=10cm,
height=10cm,
axis lines = center,
xlabel = {$x$},
ylabel = {$y$},
zlabel = {$z$},
ticks=none,
enlargelimits=0.3,
z buffer=sort,
view/h=225,
scale uniformly strategy=units only]
% this example burns colors if opacity
% is active in the document.
patch type=bilinear,
mesh/color input=explicit mathparse,
variable = \u,
variable y = \v,
domain = 0:360,
y domain = 0:180,
point meta={symbolic={0.5+0.5*y, % R
0.5+0.5*x, % G
0.5+0.5*z%B
} },
] ({cos(u)*sin(v)}, {sin(u)*sin(v)}, {cos(v)});
\draw (-1,0,0)    -- (-1.5,0,0) (0,1,0)   -- (0,1.5,0) (0,0,1)    -- (0,0,1.5);
\end{axis}
\end{tikzpicture}
\end{document}


Please not that the restriction to the RGB color model can easily be lifted: in the xcolor manual one finds the formulae that allow one to map RGB to, say, hsb or cmyk. These transformations can be added to the above.

• Nice! Thank you very much for this prompt and easy answer - I will try and fit my mapping in and see if I can realize what I am thinking about (I already have a pixel-based figure, which I don't want to use, though). I will, anyway, let you know what I am coming up with and what your answer brought me to (I just have some thinks to do at work, which distracts a little bit). :) Commented Oct 8, 2019 at 6:04