Create variable colors with decimal numbers

I created a file that looks like this, where the first column is the colored string in decimal and the second column is the y-axis. The x-axis is the line number.

0 0
1 1
2 2
...

      

Then I run this command

plot "test.dat" u 0:2:1 pt 7 ps 1 lc rgb variable 

      

As you can see in the picture, the output only contains the range from black to blue.

enter image description here

Why?

How can I create other colors?

+1


source to share


1 answer


Basically you have a choice between three options: linecolor rgb variable

, linecolor variable

and linecolor palette

. Which one you use and how depends on your actual needs.

  • When used linecolor rgb variable

    , the value given in the last column is used as the integer representation of the RGB tuple, that is, the lowest byte is the blue portion, the second lowest is the green portion, and the third byte is the red portion. This is what you have.

    To use this option, you must either have full rgb-integer values ​​in your data file, for example

    0 13.5 # black 
    0 17 
    65280 12 # green (255 * 2**8)
    0 19.3 
    16711680 14.7 # red (255 * 2**16)
    65280 10 
    16711680 22 
    
          

    and then use

    plot 'test.txt' using 0:2:1 linecolor rgb variable pt 7
    
          

    Alternatively, you store the red, green and blue components in one column each and use the gnuplot function to calculate the rgb-integer:

    0   0   0 13.5 # black 
    0   0   0 17 
    0   255 0 12 # green
    0   0   0 19.3 
    255 0   0 14.7 # red (255 * 2**16)
    0   255 0 10 
    255 0   0 22
    
          

    and then use

    rgb(r,g,b) = 65536 * int(r) + 256 * int(g) + int(b)
    plot 'test.txt' using 0:4:(rgb($1,$2,$3)) linecolor rgb variable pt 7
    
          

  • Usage linecolor variable

    will use the last column as an index linetype

    . Large indices are wrapped in a set of specific line types:

    set xrange [0:1000]
    plot '+' using 1:1:0 linecolor variable pt 7
    
          

    enter image description here

  • Usage linecolor palette

    uses the last column as an index for the color palette:

    set xrange [0:1000]
    plot '+' using 1:1:0 linecolor palette pt 7
    
          

    enter image description here



Which option you use can depend on both the number of different colors and the distribution of colors.

+3


source







All Articles