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!

  • 2
    $\begingroup$ 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!) $\endgroup$ – Pinguin Dirk Sep 4 '13 at 19:25
  • $\begingroup$ 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 :). $\endgroup$ – bob7294 Sep 4 '13 at 19:32
  • 1
    $\begingroup$ 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 :) ) $\endgroup$ – Pinguin Dirk Sep 4 '13 at 19:44
  • $\begingroup$ Related: (5087) $\endgroup$ – Mr.Wizard Sep 5 '13 at 1:41
  • $\begingroup$ Your own "filling" solution using ListLinePlot is quite ingenious IMHO. :-) $\endgroup$ – Mr.Wizard Sep 5 '13 at 1:43


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

Let (for better readability)

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.

enter image description here

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)


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

   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.

  • 2
    $\begingroup$ 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}] $\endgroup$ – ssch Sep 4 '13 at 20:08
  • 3
    $\begingroup$ 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}] $\endgroup$ – ssch Sep 4 '13 at 20:22
  • $\begingroup$ I guess I have to put "in your case" in bold... thanks for pointing that out explicitly, thanks @ssch $\endgroup$ – Pinguin Dirk Sep 4 '13 at 20:26

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];

 {Opacity[0.4], Darker@Blue, EdgeForm[Darker@Blue], 
  Polygon[Join[line1, Reverse@line2]]},

Mathematica graphics

Then one can style the polygon and/or lines as desired.

 {{Opacity[0.4], ColorData[1][3], 
   Polygon[Join[line1, Reverse@line2]]}, Thick, ColorData[1][1], 
  Line@line1, ColorData[1][2], Line@line2},

Mathematica graphics


A subtly different ListLinePlot approach:

      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:

enter image description here

  • $\begingroup$ 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. $\endgroup$ – bob7294 Sep 4 '13 at 20:26
  • $\begingroup$ This is the same way I thought of. +1 $\endgroup$ – Mr.Wizard Sep 5 '13 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?

 {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]}}

parametric plot


Use separate table for each curve or transpose the table, then use filling.

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

 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]]

enter image description here

  • $\begingroup$ This is what george2079 did in an answer before yours. $\endgroup$ – Mr.Wizard Sep 5 '13 at 7:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.