I'd like to produce a scatter plot using pgfplots
with points belonging to different classes.
The point colors should be determined through a class column in the data, which refers to an index in a colormap.
\documentclass[margin=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\pgfplotsset{colormap={mymap}{
rgb=(0.8,0.0,0.0)
rgb=(0.0,0.8,0.0)
rgb=(0.0,0.0,0.8)
}}
\begin{axis}
\addplot [
scatter,
mark=*,
only marks,
point meta=\thisrowno{2},
% colormap access=direct % NB
] table {
0 0 0
1 1 1
2 2 0
};
\end{axis}
\end{tikzpicture}
\end{document}
So far, the color mapping works as a linear map. That means:
- The outer points are rendered red (lowest meta value => lowest color value)
- The inner point is rendered blue (highest meta value => highest color value)
I'd like to use the colormap as a color palette, so that I can directly specify the used color, regardless of other points' meta value:
- The outer points should be rendered red (meta value 0 => pick color 0 from colormap)
- The inner point should be rendered green (meta value 1 => pick color 1 from colormap)
The documentation includes an example ("Lena" image), using colormap access=direct
.
It seems that it's exactly what is needed:
The choice "direct" does not perform any transformation; it interprets the value of
point meta
as integer indices into the current color map.
However, when activated, I get the following error:
Package PGF Math Error: Could not parse input '0.8,0.0,0.0' as a floating point number, sorry. The unreadable part was near ',0.0,0.0'..
There is a slew of further errors, including Runaway argument?
, but I deem them subordinate to the root error.
The error does not occur if colormap access=direct
is commented out.
The problem occurs with pdflatex, lualatex on TeX Live 2019; I also ran this on Overleaf, which uses pdflatex on TeX Live 2020, resulting in the same error.
I can think of a workaround: split the data into separate classes myself, and use one \addplot
per class, specifying the corresponding color individually. That seems cumbersome.
Do you know why the error comes up? Am I doing something wrong?