0
votes

I have data showing a change over time, and I have used Gnuplot 4.6 to generate the following plot:

Desired Gnuplot output Here, I have manually defined eleven line styles to change the color gradually from red (#ff0000) to dark red (#5f0000) as `time' progresses. Here was my input:

# svg
set terminal svg size 600,600 fname 'CMU Sans Serif' fsize '10'
set output 'plot.svg'

# color definitions
set style line 1 lc rgb '#ff0000' lt 1 lw 2 pt 7 # starting light red
set style line 2 lc rgb '#ef0000' lt 1 lw 2 pt 7 
set style line 3 lc rgb '#df0000' lt 1 lw 2 pt 7
set style line 4 lc rgb '#cf0000' lt 1 lw 2 pt 7
set style line 5 lc rgb '#bf0000' lt 1 lw 2 pt 7
set style line 6 lc rgb '#af0000' lt 1 lw 2 pt 7
set style line 7 lc rgb '#9f0000' lt 1 lw 2 pt 7
set style line 8 lc rgb '#8f0000' lt 1 lw 2 pt 7
set style line 9 lc rgb '#7f0000' lt 1 lw 2 pt 7
set style line 10 lc rgb '#6f0000' lt 1 lw 2 pt 7
set style line 11 lc rgb '#5f0000' lt 1 lw 2 pt 7

# visual elements
unset key
set xlabel 'x Axis'
set ylabel 'y Axis'

# plot data
plot for [n=2:11] 'data.dat' using 1:n with lines ls (n-1)

Is there a simpler way to get Gnuplot to gradually change the color as it plots multiple lines? I would ideally like to have a single script that can handle an arbitrary number of color gradations depending on the amount of data from the `data.dat' file.

1

1 Answers

2
votes

You can e.g. use a function which calculates the colors depending on the iteration counter

# values r, g, b, x must be in the range [0:1]
rgb(r,g,b) = (255*r*256**2 + 255*g*256 + 255*b) 
grad(x) = rgb(1 - x*0.7)
set style data lines
plot for [n=2:11] 'data.dat' using 1:2 lc rgb grad((n-2)/9.0)

Alternatively you can define a gradient and select a fractional position for each line

set palette defined (0 '#5f0000', 1 '#ff0000')
set style data lines
plot for [n=2:11] 'data.dat' using 1:2 lc palette frac (n-2)/9.0