I have been trying to change the fillstyle for the filledcurves option in gnuplot so that the fill colour represents the difference between the two curves on a 2-dimensional plot. I am thinking of this as an extension of the 'filledcurves above/below' option whereby instead of just having two colours representing above or below there is a colour range or palette.
Here is an example of the plot I would like to make from a datafile using the above/below filled curve style. A colourbar representing the y-difference between the two curves would be very useful.
I have tried to do this by adding a fourth column to the using command i.e.
plot 'data.txt' using 1:2:3:($3-$2) with filledcurves fs palette
but the filledcurves
does not appear to accept the fourth column... I have also considered trying rgb variable but this doesn't seem to work either.
I am playing around with a patch for gnuplot to allow using linecolor rgb variable
for filled curves. Then the following gnuplot code can be used:
max_color=1
# for a datafile one could extract the maximum diffference with e.g.
# stats 'hotcold.dat' using 1:($3-$2)
# max_color = (abs(STATS_min_y) > abs(STATS_max_y)) ? abs(STATS_min_y) : abs(STATS_max_y)
red(val) = (val < 0 ? abs(1+val/max_color) : 1)
green(val) = (1 - abs(val)/max_color)
blue(val) = red(-val)
rgb(val) = 65536*int(255*red(val)) + 256*int(255*green(val)) + int(255*blue(val))
set yrange[0:1]
set xrange[400:2500]
set samples 200
fhot(x) = 0.1*exp(-((x-400)/200)**2) + 0.8*exp(-((x-2000)/300)**2)
fcold(x) = 0.25*exp(-((x-700)/100)**6)+ 0.4 - (2e-4*(x-2500))**2
plot '+' using 1:(fhot($1)):(fcold($1)):(rgb(fhot($1)-fcold($1))) with filledcurves lc rgb var t '',\
'' using 1:(fhot($1)) with lines lw 4 lc rgb rgb(max_color) t 'Hot',\
'' using 1:(fcold($1)) with lines lw 4 lc rgb rgb(-max_color) t 'Cold'
That gives this result:
I haven't submitted the patch, yet, because I don't know if I understood the question correctly and because I don't know if I covered all cases. So some fine-tuning may be required.
Try to use filled histograms.
set style fill solid 1.0
plot \
datafile u 1:2:3 lt palette w boxes,\
datafile u 1:2:3 lt palette lw 2 w l
Column 3 defines color filling color according to palette settings, columns 1 and 2 define data points. You can also use background color histogram for clearing parts under graph.
I'd like to add image but I can't because of low reputation.
The trick is to draw the lines, then fill between them with filledcurves
. Here's how to do it (based on the examples at gnuplot):
set style line 2 lc rgb 'forest-green'
set style line 3 lc rgb 'plum'
set style fill pattern 5 lc 'yellow'
set xrange [0:3000]
set yrange [0:1]
plot 'data.txt' u 1:2:3 w filledcurves notitle, \
'' u 1:2 ls 2 with lines notitle, \
'' u 1:3 ls 3 with lines notitle
The output looks like this:
The data file contains these dummy values (that resemble your second graph):
500 0.90 0.90
1000 0.90 0.75
1500 0.92 0.40
2000 0.95 0.30
2500 0.94 0.23