1

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.

2
  • 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
    – Schmantii
    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. ;)
    – Schmantii
    Commented Oct 5, 2019 at 21:10

1 Answer 1

2

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.
    \addplot3 [patch,
        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}

enter image description here

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.
    \addplot3 [patch,
        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}

enter image description here

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.

6
  • 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). :)
    – Schmantii
    Commented Oct 8, 2019 at 6:04
  • @Marius OK, glad to hear, just curious what made you unaccept this answer.
    – user194703
    Commented Oct 9, 2019 at 20:46
  • I just updated my post with some of the things you proposed and with things I did during the recent days (and, of course, some new issues following). I hope it's not too messed up and I provided enough code to explain myself; let me know if there's any more code, links, information or files (e.g. log) needed! Thanks a lot for your help, really appreciate it!
    – Schmantii
    Commented Oct 9, 2019 at 20:59
  • @Marius Sorry, this is not the way this site works. If you have a follow-up question, ask a separate question. Asking questions is free of charge. In addition this has the advantage that many users see this and you get more independent opinions and suggestions.
    – user194703
    Commented Oct 9, 2019 at 21:03
  • Ooops, sorry about that; I'm just new to this site, so I'm not aware of this. I reversed the edit and gonna place a new post, referencing this old post / question, then. Thanks for telling me! :)
    – Schmantii
    Commented Oct 9, 2019 at 21:36

You must log in to answer this question.

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