I am trying to plot a set of data points (scatter
points not linked to each other), where each point has a different color. The color definition is given by predefined rgb
values written in the same file that contains the data.
The following file serves as example:
\usepackage{filecontents}
\begin{filecontents}{test.dat}
x y RED GREEN BLUE
1 11 0.2 0.3 0.5
2 14 0.3 0.3 0.4
4 26 0.1 0.8 0.1
3 39 0.0 0.1 0.9
\end{filecontents}
The x
and y
columns represent the position of the points I want to plot. The next three columns RED
, GREEN
and BLUE
correspond to the associated color values in rgb
format.
What I was trying so far, was to do:
\begin{document}
\pgfplotstableread{test.dat}\test
%number of points to be plotted
\pgfplotstablegetrowsof{\test}
\pgfmathsetmacro{\N}{\pgfplotsretval-1}
\begin{tikzpicture}
\begin{axis}[%
xmin=0, xmax=5,
ymin=0, ymax=45,
width=8cm,
height=6cm,
grid=both,
xlabel=Xtest,
ylabel=Ytest,
]
\foreach \i in {0,...,\N}
{
\definecolor{testcolor}{rgb}{\thisrow{3}, \thisrow{4}, \thisrow{5}}
\addplot[scatter,
only marks,
scatter/use mapped color={draw=none,fill=testcolor},
]
table [x index = 0,y index = 1]{\test};
}
\end{axis}
\end{tikzpicture}
\end{document}
But I am unable to fetch a single row value for the color definition. How can I do this ? I also looked at meta
options, but the color is defined with a single value (linearly) and I need the three components in the color definition.
x | y | RED1 | GREEN1 | BLUE1 | RED2 | GREEN2 etc.
where x and y are columns of n elements, but RED1, GREEN1 etc are columns of only 1 element... This would result in a file with 3*n+2 rows, but it might be better than nothing!x
andy
asx1 | y1 | RED1 | GREEN1 | BLUE1 | x2 | y2 | ...
It's not really what I'm looking for. There has to be a way to read the table row by row...