问题
I would like to change the color of a plot according to the x-value, for a function plot (i.e. not from a data file).
For example, I define a palette as follows: set palette defined ( 0 'purple', 1 'blue', 2 'green', 3 'yellow', 4 'orange', 5 'red' )
and I wish to use the color the function sin(x) using my palette according to the x value for the range [0:5].
How can this be done?
回答1:
You can use linecolor palette for this purpose, which requires the specification of an additional column that contains the color information. For a function plot you can use the special filename '+' to have the full versatility of the using command at your disposal:
set palette defined ( 0 'purple', 1 'blue', 2 'green', 3 'yellow', 4 'orange', 5 'red' )
set xrange [0:5]
plot '+' using 1:(sin($1)):1 with lines linewidth 3 linecolor palette
来源:https://stackoverflow.com/questions/49825712/gnuplot-coloring-a-plot-according-to-x-value