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
Another awkward workaround: instead of filledcurves using thick vertical vector lines.
This will work when you have functions like in the example or equidistant data in x. If you don't have equidistant data in x, you would have to interpolate. Unfortunately, gnuplot does not have a feature for interpolating or resampling. You either can do this with external tools or neverthless with gnuplot which is getting a bit lenghty, see here: Resampling data with gnuplot
For getting a good-looking color gradient you have to adjust the graph/canvas size, the sampling and/or the linewidth in order to find an optimum to eliminate gaps, overhang or aliasing.
Too thin (lw 1) and too thick (lw 8) are not good. In the example below lw 3 seems to be a reasonable value. Maybe there are more ways to further optimize.
The example below is using @Christoph's code, slightly modified.
Code:
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)):(0):(fcold($1)-fhot($1)):(rgb(fhot($1)-fcold($1))) with vectors nohead lw 3 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'
Result: (wxt 640x480, lw 1)
Result: (wxt 640x480, lw 3)
Result: (wxt 640x480, lw 8)