producing variable colors with decimal numbers

前端 未结 1 1728
既然无缘
既然无缘 2021-01-25 14:58

I created a file which looks like where the first column is the color line in decimal and the second column is y-axis. The x-axis is the row number.

0 0
1 1
2 2
         


        
相关标签:
1条回答
  • 2021-01-25 15:39

    Basically you have the choice between three options, linecolor rgb variable, linecolor variable and linecolor palette. Which one you use and how depends on your actual requirements.

    1. When you use linecolor rgb variable, the value given in the last column is used as integer representation of an rgb-tuple, i.e. the lowest byte is the blue part, the second lowest the green part and the third byte is the red component. This is what you have.

      For using this option you must either have the full rgb-integer values in your data file, like

      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 save the red, green and blue components in one column each and use a 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
      
    2. Using linecolor variable would use the last column as linetype index. Large indices are wrapped to the set of defined linetype:

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

      enter image description here

    3. Using linecolor palette uses the last column as index for the color palette:

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

      enter image description here

    Which variant you use may depend both on the number of different colors and the distribution of the colors.

    0 讨论(0)
提交回复
热议问题