Related to Set variable textcolor and point color with labels style in gnuplot but not quite the same. I have a set of data in the file "test.dat":
643.8 0.09417 28.9 00 24 255 0
483.1 0.09232 28.0 01 255 0 120
518.5 0.08943 29.6 02 11 65 255
I want a 3D plot where the first three comlumns are interpreted as x y z coordinates and the fourth column as a label/point symbol and then I want the label color coded in RGB which should be taken from the 5. 6. and 7th column. I try this:
rgb(r,g,b) = 65536 * int(r) + 256 * int(g) + int(b)
splot "test.dat" u 1:2:3:4:(rgb($5/255,$6/255,$7/255)) with labels tc rgb variable notitle
but the labels appear in black:
What am I doing wrong?
>Solution :
You have been close, but why do you divide your column values by 255?
Some comments:
- In the example below I used, e.g.
column(5)instead of the shorter$5, because in some cases you might have to escape$and use\$5instead. So,column(5)is longer but "universal". And instead of5you could also use a variable. - it’s not necessary to use
int(). gnuplot will truncate. - you can also use hexadecimal numbers
0x10000and0x100to multiply your R,G,B values with (easier to remember and less prone to typos).
Script:
### variable label color from R,G,B columns
reset session
$Data <<EOD
643.8 0.09417 28.9 00 24 255 0
483.1 0.09232 28.0 01 255 0 120
518.5 0.08943 29.6 02 11 65 255
EOD
rgb(colR,colG,colB) = 0x10000*column(colR) + 0x100*column(colG) + column(colB)
splot $Data u 1:2:3:4:(rgb(5,6,7)) w labels tc rgb var
### end of script
Result:

