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.