a different ben
a different ben

Reputation: 4008

In gnuplot how can I set rgb colour from 3 columns?

I have 3 'columns' in my data file that specify the red, green, and blue fractions:

red     green   blue
0.263   0.914   0.086
0.263   0.914   0.086
0.263   0.914   0.086
1.000   0.571   0.429
1.000   0.571   0.429

How can I use these to plot some other columns painted by these values? Apparently the following method is only available in 3D plots with splot:

rgb(r,g,b)=<some function code>
plot './data.csv' u 1:2:(rgb($8,$9,$10)) w l rgb variable

I can't see how I can use these values to colour the plot.

Upvotes: 1

Views: 3782

Answers (1)

mgilson
mgilson

Reputation: 309831

Have a look at the gnuplot demo rgb_variable.dem. The corresponding data file looks like this:

0   0   0   0x000000
255 0   0   0xff0000
255 255 0   0xffff00
255 255 255 0xffffff
0   255 255 0x00ffff
255 0   255 0xff00ff
0   255 0   0x00ff00
#<snip> 
#...
#</snip>

Note that the 4th column isn't used until the last example -- i.e. this is almost what you have. You'll have an additional transform to take your colors from the range [0-1] to the range [0-255], but that's an easy one (just multiply by 255):

scale(x)=x*255
rgb(r,g,b) = int(scale(r))*65536 + int(scale(g))*256 + int(scale(b))
plot './data.csv' u 1:2:(rgb($8,$9,$10)) with lines linecolor rgb variable
#                                                   ^^^^^^^^^ don't forget this:-)

Upvotes: 3

Related Questions