# Filling area under line with lowest value

How to use Fill but only under the line which has the lowest value on plot? Consider following code:

data = Table[#, {x,-5,10,1}]&/@{{x, 2 x + 3}, {x, 5 x + 2}, {x, -3 x + 20}, {x, 5}}
ListLinePlot[data]


Which gives a plot:

And that's how it should look:

Since the plots will not always be the same, the bottom lines are changing so I can't just hardcode it

xylst = {{x, 2 x + 3}, {x, 5 x + 2}, {x, -3 x + 20}, {x, 5}};

data = Table[#, {x, -5, 10, 1}] & /@ xylst;

ylst = xylst[[All, -1]];

celst = Table[ConditionalExpression[f, f == Min[ylst]], {f, ylst}];

Show[ListLinePlot @ data,
Plot[celst, {x, -5, 10}, Filling -> Bottom]]


Alternatively, use ylst and celst with Plot:

Plot[Evaluate @ Join[ylst, celst], {x, -5, 10},
PlotStyle -> ColorData[97] /@ Range[4],
Filling -> Thread[Range[5, 8] -> Bottom]]


Update: If we have access only to data (not the functions used to generate data):

iFlst = Interpolation /@ data;

cElst = Table[ConditionalExpression[f[x],
f[x] == Min[Through@iFlst@x]], {f, iFlst}];

Plot[Evaluate @ Join[Through @ iFlst @ x, cElst],
{x, Min @ data[[All, All, 1]], Max @ data[[All, All, 1]]},
PlotStyle -> (ColorData[97] /@ Range[Length @ iFlst]),
Filling -> Thread[Length @ iFlst + Range[Length @ iFlst] -> Bottom]]


• Great answer! Works perfect. Thank you! Apr 27, 2023 at 9:32