# Background color depending on external function value on the same plot

I would like to plot a two dimensional list (ListPLot [{x, y[x]}]) where the background color is changing with x value according to the value assumend by an external function f[x]. Thank you. Sorry, I have to be more precise. This is what I mean fo the function Plot

f[x_] := 6 E^-x Sin[2*Pi*x^2];
g[x_] := Sin[2*x*10];
Plot[{f[x], ConditionalExpression[0, g[x] < 0]}, {x, 0, 2},
PlotStyle -> {Black, None},
Filling -> {2 -> {Bottom, Red}, 2 -> {Top, Red}}]

I would like to be the same working with list and ListLinePLot.

• Can you make the question more specific and concrete by assigning functions to y and f?
– Syed
Commented Mar 19, 2023 at 11:51
• Are you really talking about background color (e.g. something like ContourPlot), or do you want to change the color of the individual points according to your function f[x]? Commented Mar 19, 2023 at 13:30
• I think the OP wants a DensityPlot in the background with a ListLinePlot in the foreground.
– Syed
Commented Mar 19, 2023 at 13:34

• Plot.
f[x_] := 6 E^-x Sin[2*Pi*x^2];
g[x_] := Sin[2*x*10];
Plot[{f[x], f[x]}, {x, 0, 2},
ColorFunction -> Function[{x, y}, ColorData["TemperatureMap"][g@x]],
ColorFunctionScaling -> True, Filling -> {{1 -> Bottom}, {2 -> Top}},
Epilog ->
Plot[f[x], {x, 0, 2},
PlotStyle -> {AbsoluteThickness[2], White}][[1]]]

• ListPlot+ Joined -> True
f[x_] := 6 E^-x Sin[2*Pi*x^2];
g[x_] := Sin[2*x*10];
data = Table[{x, f[x]}, {x, 0, 2, .1}];
ListPlot[{data, data}, Joined -> True,
ColorFunction -> Function[{x, y}, ColorData["TemperatureMap"][g@x]],
ColorFunctionScaling -> True, Filling -> {{1 -> Bottom}, {2 -> Top}},
Epilog -> ListPlot[data, PlotStyle -> White, Joined -> True][[1]]]

• ListPlot+ Joined -> False

• No, I would like to work with the list, so ListPlot, not PLot. Commented Mar 19, 2023 at 14:24
• This solution is quite good but seems rather contrived; thank you. Is there another solution? More direct. Besides, a red stripe is sufficient! Directly on the background Commented Mar 20, 2023 at 6:56