# Filling between parametric plots

I am new with Mathematica, but am trying to fill an area between two parametric plots

ParametricPlot[{{u + Sin[u], -Cos[u]}, {u + Sin[u + Pi], Cos[u + Pi]}},
{u, 0, Pi}, Axes -> True ]


which thus far are nice, clean curves: Thanks to the answers here: How do I fill in a circle made by ParametricPlot with one solid color? I became aware of ListLinePlot.

However, my ListLinePlot for this situation

ListLinePlot[Table[{{u + Sin[u], -Cos[u]}, {u + Sin[u + Pi], Cos[u + Pi]}},
{u, 0, Pi, 0.0005}], Mesh -> All,
MeshStyle -> Directive[AbsolutePointSize[0.0005], Black],
PlotStyle -> Directive[Thin, LightGray]] does not seem to give as good a resolution no matter how finely I subdivide the interval, and also produces problems with self-intersection near the boundaries when plotting several periods. In particular, the contrast with similar curves filled in Plot is striking.

Is there a smarter way to fill the area between these parametric curves? Perhaps using something else than ListLinePlot? Thanks!

• Don't accept my answer all too quickly! I am sure there are other approaches, give them a chance too :) (by the way: welcome to mathematica.se, great way to present a first question!) Sep 4, 2013 at 19:25
• Thanks for the welcome, and the helpful answer. Using ParametricPlot in the way you suggest gives me full resolution, without the somewhat artificial contrivance of ListLinePlot drawing vertical lines between the two data sets to fill the area. I have tentatively "unaccepted" to allow other people to give their input, but hope to reverse that soon :). Sep 4, 2013 at 19:32
• Great! Note that you got the vertical lines as you missed to Transpose your data in ListLinePlot, thus it connected 2 points of each curve instead of the points on the curve. See ListLinePlot docu. I also added more info in my answer (and don't forget, you can still upvote :) ) Sep 4, 2013 at 19:44
• Related: (5087) Sep 5, 2013 at 1:41
• Your own "filling" solution using ListLinePlot is quite ingenious IMHO. :-) Sep 5, 2013 at 1:43

ParametricPlot

Here's a way that seems to work in your case (see below in @ssch's (thanks!) comments when it doesn't)

f1[u_] := {u + Sin[u], -Cos[u]}
f2[u_] := {u + Sin[u + Pi], Cos[u + Pi]}


And then

ParametricPlot[{ v f1[u] + (1 - v) f2[u]}, {u, 0, Pi}, {v, 0, 1},
Axes -> True, Mesh -> None, PlotStyle -> LightGray]


i.e., we just add an auxiliary parameter v, to "shift" between the curves. Using ColorFunction, you can add more colors:

ParametricPlot[{v f1[u] + (1 - v) f2[u]}, {u, 0, Pi}, {v, 0, 1},
Axes -> True, Mesh -> None, ColorFunction -> Function[{x, y, u, v}, Hue[v]]]


(I won't paste a picture of that here)

ListLinePlot

For ListLinePlot, note that your data is wrongly formatted, try e.g.:

ListLinePlot[
Transpose@Table[{{u + Sin[u], -Cos[u]}, {u + Sin[u + Pi], Cos[u + Pi]}},
{u, 0, Pi, 0.01}], Filling -> {1 -> {2}}]


Note the Transpose I added to fix the issue.

• Visualization of the ParametricPlot procedure: Manipulate[ ParametricPlot[{ v f1[u] + (1 - v) f2[u], f1[u], f2[u]}, {u, 0, Pi}, Epilog -> { Point[{f1[û], f2[û]}], Line[{f1[û], f2[û]}]}] , {{v, .5}, 0, 1} , {{û, 2.}, 0, Pi}]
– ssch
Sep 4, 2013 at 20:08
• More instructive when it fails: f1[u_] := {u + Sin[u], -Cos[u]}; f2[u_] := {u + Sin[u + Pi], Cos[2 (u - Pi/2) + Pi]}; pp = ParametricPlot[{v f1[u] + (1 - v) f2[u]}, {u, 0, Pi}, {v, 0, 1}, Mesh -> None]; Manipulate[ Show[ pp, Epilog -> {Line[{f1[u], f2[u]}]} ], {{u, 0.5}, 0, Pi}]
– ssch
Sep 4, 2013 at 20:22
• I guess I have to put "in your case" in bold... thanks for pointing that out explicitly, thanks @ssch Sep 4, 2013 at 20:26
• How would you do it if instead of two curves there were several that form a closed loop ? Mar 1 at 13:49

Similar to @ybeltukov, you can extract the lines from the plot. But to get a proper polygon, you need to reverse one of the lines.

plot = ParametricPlot[{{u + Sin[u], -Cos[u]}, {u + Sin[u + Pi],
Cos[u + Pi]}}, {u, 0, Pi}, Axes -> True];
{line1, line2} = Cases[plot, l_Line :> First@l, Infinity];

Graphics[
{Opacity[0.4], Darker@Blue, EdgeForm[Darker@Blue],
Polygon[Join[line1, Reverse@line2]]},
Options[plot]
] Then one can style the polygon and/or lines as desired.

Graphics[
{{Opacity[0.4], ColorData,
Polygon[Join[line1, Reverse@line2]]}, Thick, ColorData,
Line@line1, ColorData, Line@line2},
Options[plot]
] A subtly different ListLinePlot approach:

ListLinePlot[{
Table[{u + Sin[u], -Cos[u]}, {u, 0, Pi, 0.005}],
Table[{u + Sin[u + Pi], Cos[u + Pi]}, {u, 0, Pi, 0.005}]},
Filling -> {1 -> {{2}, LightGray}}, PlotStyle -> Black]


It looks better to me in terms of jaggies: • Thanks. I think this addresses the issue pointed out by Pinguin Dirk in the comments as well as in his answer: my ListLinePlot data needs to be transposed - the resolution problems stem from this. Sep 4, 2013 at 20:26
• This is the same way I thought of. +1 Sep 5, 2013 at 1:46

I think you can use Piecewise and the approach in your link How do I fill in a circle made by ParametricPlot with one solid color?

ParametricPlot[
{Piecewise[{{u + Sin[u], u < Pi}, {u - Pi + Sin[u], u > Pi}}],
Piecewise[{{-Cos[u], u < Pi}, {Cos[u], u > Pi}}]},
{u, 0, 2 Pi}, Axes -> True] /. Line[l_List] :> {{Red, Polygon[l]}, {Black, Line[l]}} Use separate table for each curve or transpose the table, then use filling.

ListLinePlot[
Table[#, {u, 0, Pi, Pi/100}] & /@  {{u + Sin[u], -Cos[u]},
{u + Sin[u + Pi], Cos[u + Pi]}},
Filling -> {1 -> {2}}, FillingStyle -> GrayLevel[.95]];

ListLinePlot[
Transpose[Table[{{u + Sin[u], -Cos[u]}, {u + Sin[u + Pi], Cos[u + Pi]}},
{u, 0, Pi, Pi/100}]],
Filling -> {1 -> {2}}, FillingStyle -> GrayLevel[.95]] • This is what george2079 did in an answer before yours. Sep 5, 2013 at 7:35

I tried just :

ListLinePlot[
Table[#, {u, 0, Pi, Pi/100}] & /@  {{u + Sin[u], -Cos[u]},
{u + Sin[u + Pi], Cos[u + Pi]}},
Filling -> {1 -> {2}}, FillingStyle -> Green[.95]];


And it made the same figure but the color of filling is blue between the curves. So why do you need the transpose version also?