# Filling in Show[]

Is it possible to fill the region between two ListPlots' in Show[]. Something like:

plot1 = ListPlot[f1,Joined->True]
plot2 = ListPlot[f2,Joined->True]
both = Show[plot1,plot2,Filling->{1->{2}}]


my lists f1 and f2 are huge and complicated and has to be computed and plotted separately, i.e. a solution of the form ListPlot[f1,f2,{x,xmin,xmax},Filling->...] is not what I'm looking for. Is this possible and how?

Minimal Example:

list1 = Table[-(x - 2)^2 + 1, {x, 0, 3, 0.1}];
list2 = Table[(x - 1)^2, {x, 0, 3, 0.1}];
plot1 = ListPlot[list1, Joined -> True,DataRange -> {0, 3}]
plot2 = ListPlot[list2, Joined -> True,DataRange -> {0, 3}]
both = Show[plot1,plot2]


Here I would like the region between the plots shaded.

The lists list1 and list2 two themselves are lists/matrices. They have dimensions such as 6 times 110 each. Then the object temp = {list1, list2} has Dimension[temp] = {2,6,110} which cannot be ListPlotted straight away.

• Just join f1and f2points in the same ListPlot, whatever your lists will be. Isn't contradictory to plot each list separately, to combine them afterwards with Show instead of plotting them together with ListPlot? Jan 30, 2018 at 18:09
• One could do that but rather not in this case. Jan 30, 2018 at 18:14
• Doesn't the following work? ListPlot[{list1, list2}, Joined -> True, DataRange -> {0, 3}, Filling -> {2 -> {1}}].
– JimB
Jan 30, 2018 at 18:37
• @JimB I added some more info to my question (final paragraph). Feb 1, 2018 at 16:15
• If the dimensions of list1 and list2 are {110,6} and the horizontal and vertical coordinates are in respective positions 3 and 5 in the list of 6 variables, then you could certainly use ListPlot[{list1[[All, {3 5}]], list2[[All, {3, 5}]]}].
– JimB
Feb 1, 2018 at 16:35

If you must do this after the lists have been plotted, you can simply grab the lists from the plot,

lines = FirstCase[#, Line[x_] :> x, Nothing, Infinity] & /@ {plot1,
plot2};
ListLinePlot[lines, Filling -> {1 -> {2}}]


• Well actually I have solved my problem since writing the question (by simply saving the lists separately and then ListPlot them together, hence no need for new code etc) but I'll leave the question alone since it has engaged some people. Thanks anyway! Jan 30, 2018 at 18:52
• Could add your solution as an answer as well, in case anyone else stumbles upon this in the future :)
– ktm
Feb 1, 2018 at 16:18
• We're working on the solution :-) but the question differs from this in that there we shade the region before using Show : mathematica.stackexchange.com/q/164961/10325 Feb 1, 2018 at 17:23
• @user6014 The solution is in this link mathematica.stackexchange.com/a/164969/10325 Feb 1, 2018 at 19:10

Here's one way to manually tackle the problem. Might be a little rough around the edges and need some clean up to be more robust, but its a start.

Generate polygon filling:

f1 = Table[{x, Sin[x]}, {x, 0, 10, .1}];
f2 = Table[{x, Cos[x]}, {x, 0, 10, .1}];
mins = If[#[[1, 2]] < #[[2, 1]], #[[1]], #[[2]]] & /@
Transpose[{f1, f2}];
maxes = If[#[[1, 2]] < #[[2, 1]], #[[2]], #[[2]]] & /@
Transpose[{f1, f2}];
joined = Join[mins, Reverse@maxes];
gr = Graphics[{LightBlue, Polygon[joined]}]


Combine with ListPlots:

plot1 = ListPlot[f1, Joined -> True];
plot2 = ListPlot[f2, Joined -> True];
both = Show[{plot1, plot2, gr}]


• For this to work one needs to now the analytic form of the lists right (or at least a fit to them)? Jan 30, 2018 at 18:17
• I don't think so, I think the biggest requirement for this is that the two lists have points that line up exactly on the same x coordinates, like in your minimal example.
– ktm
Jan 30, 2018 at 18:18
• If they are parallel, you know that one list is always has a value lesser than the other list for every x value, so you can just do f1 = Table[{x, 2 x + 1}, {x, 0, 10, .1}]; f2 = Table[{x, 2 x + 2}, {x, 0, 10, .1}]; joined = Join[f1, Reverse@f2]; gr = Graphics[{LightBlue, Polygon[joined]}] without picking mins/maxes programmatically. If almost parallel means they still intersect than this isn't relevant.
– ktm
Jan 30, 2018 at 18:28