0
votes

I am currently working on a project where I need to plot a set of functions and fill the area between them.

I have tried different things, but I cannot really get it to work.

Here is a simplified version of the gnuplot script:

f(x) = 80
g(x) = 0.35*x - 7.5
h(x) = -1.96629*x + 710
i(x) = -80
j(x) = -0.35*x + 7.5
k(x) = 1.96629*x -710

set xzeroaxis
set xtics axis
set xrange [0:500]

set yzeroaxis
set ytics axis
set yrange [-200:200] 

set border 0
plot f(x) with lines ls 1 lt rgb "red", \
g(x) with lines ls 1 lt rgb "red", \
h(x) with lines ls 1 lt rgb "red", \
i(x) with lines ls 1 lt rgb "blue", \
j(x) with lines ls 1 lt rgb "blue", \
k(x) with lines ls 1 lt rgb "blue" 

This produces the following plot:

Plot of multiple functions I have tried different things and this link got me some of the way, but I am running out of ideas.

So my question goes: is it possible to fill the area between the red and blue lines (I.e the convex space that the functions form)?

2

2 Answers

1
votes

You can do it easily if you already know which curves are lower bounds and which are upper bounds:

max(a,b)=(a>b)?a:b
min(a,b)=(a<b)?a:b
lowerb(x)=max(max(i(x),j(x)),k(x))
upperb(x)=min(min(f(x),g(x)),h(x))
plot "+" using 1:((lowerb($1)<upperb($1))?lowerb($1):1/0):(upperb($1)) with filledcurves

The ternary operator in the plot command allows to plot only { lowerb(x)< y <upperb(x)} and not { lowerb(x) > y > upperb(x)}

If you have a very long list of functions, it should be possible to automate the construction of lowerb and upperb using a macro.

0
votes

Use the ternary operator to define piece wise the red function. Call it f1. Plot f1 and -f1 with filledcurves. I think that approach should do it.