[Tex/LaTex] How to use colors from a pgfplots colormap in own draw

pgfplotstikz-pgf

Let's consider a set of ellipses (or say a signal), here 3, but in general that might be a huge array of 64x64

\documentclass{standalone}
\usepackage{tikz,pgfplots}

\usetikzlibrary{calc}

\begin{document}
    \begin{tikzpicture}
            \draw[rotate around={-20:(0,0)},black] (0,0) ellipse (.5 and .25);
            \draw[rotate around={0:(1,0)},black] (1,0) ellipse (.45 and .3);
            \draw[rotate around={20:(2,0)},black] (2,0) ellipse (.4 and .35);
    \end{tikzpicture}
\end{document}

And I further have values from 0 to 1 for each ellipse indicating a color, that is i would like to replace the black by some color from a colormap, maybe the /pgfplots/colormaps/hue colormap. Let these values for example be

 {0.2, 0.6, 0.3}

The I would like to read the colormap values at these points and use them to fill (or draw) the ellipses.

So for short the question is: How can I access a specific color in a pgfplots-colormap?

Best Answer

As with the release of PGFPlots v1.13 you can use the new keys color of colormap or index of colormap to get easy access to the colors of the colormap. See section 4.7.6 pages 192f in the manual.

Here your code again using the first mentioned feature

\documentclass{standalone}
\usepackage{pgfplots}
    \usepgfplotslibrary{colormaps}
    \pgfplotsset{compat=1.11}
    \tikzset{
        ellC/.style={
            color of colormap={#1},
            draw=.!80!black,
            fill=.!80!white,
        },
    }
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            hide axis,
            colormap/hsv,
            xmin=-2.5, xmax=2.5,
            ymin=-.5, ymax=.5,
            axis equal,
        ]
            \draw[ellC=200, rotate around={-20:(0,0)}] (0,0) ellipse (.5  and .25);
            \draw[ellC=600, rotate around={0:(1,0)}]   (1,0) ellipse (.45 and .3);
            \draw[ellC=300, rotate around={20:(2,0)}]  (2,0) ellipse (.4  and .35);
        \end{axis}
    \end{tikzpicture}
\end{document}

image of the result of above code