问题
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.
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 22and then use
plot 'test.txt' using 0:2:1 linecolor rgb variable pt 7Alternatively 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 22and 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 7Using
linecolor variablewould use the last column aslinetypeindex. Large indices are wrapped to the set of defined linetype:set xrange [0:1000] plot '+' using 1:1:0 linecolor variable pt 7
Using
linecolor paletteuses 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

