producing variable colors with decimal numbers

一曲冷凌霜 提交于 2019-12-20 04:21:21

问题


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
...

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 contains a range of black to blue colors only.

Why?

How can I produce other colors?


回答1:


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
    

  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
    

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



来源:https://stackoverflow.com/questions/25865368/producing-variable-colors-with-decimal-numbers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!