3

Reading this and this answer I understood that changing the colours of every point is possible, but:

  • it has to be defined using set palette model RGB defined (), hence if I want 100 different colours I will have to define all of them

  • the colour of the point is specified just before it is drawn.

My question is, is there a way to avoid all of the above, for example modify my data file as follows:

x y z R   G   B
1 2 3 0   255 255 
5 6 2 255 0   0

And have the according point drawn with the specified colour?

Community
  • 1
  • 1
Alexandru Barbarosie
  • 2,952
  • 3
  • 24
  • 46
  • See also my answer to [producing variable colors with decimal numbers](http://stackoverflow.com/q/25865368/2604213). – Christoph Oct 24 '14 at 18:20

1 Answers1

4

Try the following on gnuplot 4.6+:

rgb(r,g,b) = 65536 * int(r) + 256 * int(g) + int(b)
plot "data.dat" using 1:2:(rgb($3,$4,$5)) with points lc rgb variable

From the manual:

1.17.1.3 rgbcolor variable

variable tells the program to read RGB color information for each line in the data file. This requires a corresponding additional column in the using specifier. The extra column is interpreted as a 24-bit packed RGB triple. If the value is provided directly in the data file it is easiest to give it as a hexidecimal value (see 'rgbcolor'). Alternatively, the using specifier can contain an expression that evaluates to a 24-bit RGB color as in the example below. Text colors are similarly set using tc rgbcolor variable.

Fabio A. Correa
  • 1,968
  • 1
  • 17
  • 26
  • If you could be so kind, and extend your answer to one more thing, I am plotting not points but rather lines, what happens if I change `points` to `lp` is that the line has the colour of the point I start with, is there a way I could make the colour of the line different/a colour that will translate from begin->end. A source where I could read on this would be good as well. – Alexandru Barbarosie Oct 24 '14 at 00:23
  • Unfortunately there is no direct solution for this one; each line segment will be drawn with a color; gradients need an indirect, complex approach. See [here](http://www.gnuplotting.org/using-a-palette-as-line-color/) and [here](http://gnuplot-surprising.blogspot.com/2011/09/gradient-colored-curve-in-gnuplot0.html). – Fabio A. Correa Oct 24 '14 at 00:39