Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Gnuplot lables in RGB colors read from data line

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

X11 Window of gnuplot showing three positioned labels in black instead of inteded rgb colors

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 \$5 instead. So, column(5) is longer but "universal". And instead of 5 you could also use a variable.
  • it’s not necessary to use int(). gnuplot will truncate.
  • you can also use hexadecimal numbers 0x10000 and 0x100 to 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:

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading