7

I have the following simple PGFPlots sample

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}

\begin{axis}[
xmin=0, xmax=1,
ymin=0, ymax=1,
width=7.5cm,
colorbar,
colormap={mymap}{[1pt]
  rgb(0pt)=(0,0,0.5);
  rgb(22pt)=(0,0,1);
  rgb(25pt)=(0,0,1);
  rgb(68pt)=(0,0.86,1);
  rgb(70pt)=(0,0.9,0.967741935483871);
  rgb(75pt)=(0.0806451612903226,1,0.887096774193548);
  rgb(128pt)=(0.935483870967742,1,0.0322580645161291);
  rgb(130pt)=(0.967741935483871,0.962962962962963,0);
  rgb(132pt)=(1,0.925925925925926,0);
  rgb(178pt)=(1,0.0740740740740741,0);
  rgb(182pt)=(0.909090909090909,0,0);
  rgb(200pt)=(0.5,0,0)
},
point meta min=12.0628665990324,
point meta max=98.5559785610705,
colorbar style={
  ytick={20,30,40,50,60,70,80,90},
  yticklabels={20,30,40,50,60,70,80,90}
}
]

\path [draw=black, fill=blue, opacity=0.4]
(axis cs:0.722443382570222,0.322958913853178)--
(axis cs:0.361788655622314,0.228263230878956)--
(axis cs:0.293714046388829,0.630976123854488)--
cycle;

\end{axis}

\end{tikzpicture}
\end{document}

and would like to fill the path with a value of the colormap, i.e., point meta. How to?

0

2 Answers 2

8

This requires direct access to the colormap functions of pgfplots:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}

\begin{axis}[
xmin=0, xmax=1,
ymin=0, ymax=1,
width=7.5cm,
colorbar,
colormap={mymap}{[1pt]
  rgb(0pt)=(0,0,0.5);
  rgb(22pt)=(0,0,1);
  rgb(25pt)=(0,0,1);
  rgb(68pt)=(0,0.86,1);
  rgb(70pt)=(0,0.9,0.967741935483871);
  rgb(75pt)=(0.0806451612903226,1,0.887096774193548);
  rgb(128pt)=(0.935483870967742,1,0.0322580645161291);
  rgb(130pt)=(0.967741935483871,0.962962962962963,0);
  rgb(132pt)=(1,0.925925925925926,0);
  rgb(178pt)=(1,0.0740740740740741,0);
  rgb(182pt)=(0.909090909090909,0,0);
  rgb(200pt)=(0.5,0,0)
},
point meta min=12.0628665990324,
point meta max=98.5559785610705,
colorbar style={
  ytick={20,30,40,50,60,70,80,90},
  yticklabels={20,30,40,50,60,70,80,90}
}
]

\path [
    /utils/exec={
        % map linearly from [0:1000] into the colormap. 500 is in the
        % middle:
        \pgfplotscolormapdefinemappedcolor{500}
    },
    draw=black, fill=mapped color]
(0,0)-- (0.5,0.2) -- (0,0.4) -- cycle;

\path [
    /utils/exec={
        \pgfplotsset{colormap access=direct}
        % direct access using an index. Yours has 201 elements:
        \pgfplotscolormapdefinemappedcolor{127}
    },
    draw=black, fill=mapped color]
(0.722443382570222,0.322958913853178)--
(0.361788655622314,0.228263230878956)--
(0.293714046388829,0.630976123854488)--
cycle;


\end{axis}

\end{tikzpicture}
\end{document}

enter image description here

Since there is currently no key of sorts "use color map value", you have to resort to the macro which defines mapped color as outlined above. I used /utils/exec, a way of PGF which allows you to invoke a macro in a context where key-value pairs are expected.

5

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.

\documentclass{standalone}
\usepackage{pgfplots}
    \pgfplotsset{compat=newest}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            xmin=0, xmax=1,
            ymin=0, ymax=1,
            width=7.5cm,
            colorbar,
            colormap={mymap}{[1pt]
                rgb(0pt)=(0,0,0.5);
                rgb(22pt)=(0,0,1);
                rgb(25pt)=(0,0,1);
                rgb(68pt)=(0,0.86,1);
                rgb(70pt)=(0,0.9,0.967741935483871);
                rgb(75pt)=(0.0806451612903226,1,0.887096774193548);
                rgb(128pt)=(0.935483870967742,1,0.0322580645161291);
                rgb(130pt)=(0.967741935483871,0.962962962962963,0);
                rgb(132pt)=(1,0.925925925925926,0);
                rgb(178pt)=(1,0.0740740740740741,0);
                rgb(182pt)=(0.909090909090909,0,0);
                rgb(200pt)=(0.5,0,0)
            },
            point meta min=12.0628665990324,
            point meta max=98.5559785610705,
            colorbar style={
                ytick={20,30,40,50,60,70,80,90},
                yticklabels={20,30,40,50,60,70,80,90},
            }
        ]

            \path [color of colormap=500,draw=.!80!black, fill=., opacity=0.4]
                (0,0)-- (0.5,0.2) -- (0,0.4) -- cycle;

            \path [index of colormap=128,draw=.!80!black, fill=., opacity=0.4]
                (0.722443382570222,0.322958913853178) --
                (0.361788655622314,0.228263230878956) --
                (0.293714046388829,0.630976123854488) --
                cycle;

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

image showing the result of above code

You must log in to answer this question.

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