10
$\begingroup$

Context

I want to do Filled plot such as:

dat1 = {Table[{i^2, i + 1}, {i, 5}], Table[{i^2, i}, {i, 5}]}
ListLinePlot[dat1, PlotStyle -> Red, Filling -> {1 -> {2}}]

Mathematica graphics

But when I apply this to my own data:

dat = 
{
  {{3.0779456558039593`, 3.842486584798708`}, 
   {1.2951669675555262`, 4.05402324780319`}, 
   {0.9196161755899819`, 3.939944632202657`}, 
   {0.5722748507275665`, 3.8875332289711`}, 
   {0.29373287932080444`, 3.7317102841786385`}},
  {{3.0779456558039593`, 7.125115694053534`}, 
   {1.2951669675555262`, 5.8724983311100605`}, 
   {0.9196161755899819`, 5.707473500231869`}, 
   {0.5722748507275665`, 5.114513590881306`}, 
   {0.29373287932080444`, 4.240800591615147`}}
}

It fails to fill the region:

ListLinePlot[dat, PlotStyle -> Red, Filling -> {1 -> {2}}]

Mathematica graphics

Question

Am I missing something obvious?

$\endgroup$
1
  • $\begingroup$ See update to my answer for brief discussion of why this is not a bug. $\endgroup$
    – rcollyer
    Oct 1, 2015 at 21:05

1 Answer 1

12
$\begingroup$

The cause is your data is out of order. So, the workaround is

ListLinePlot[SortBy[First] /@ dat, PlotStyle -> Red, 
  Filling -> {1 -> {2}}]

enter image description here

I believe it is not a bug. Or, at least, it is an issue that is tangentially discussed in the ListLinePlot documentation. So, while this is certainly disconcerting to see, unusual behavior with unsorted data is expected.

$\endgroup$
3
  • 3
    $\begingroup$ its actually just reversed.. so Reverse /@ dat works too. $\endgroup$
    – george2079
    Oct 1, 2015 at 20:33
  • $\begingroup$ @rcollyer thanks! Should I leave the question for reference? $\endgroup$
    – chris
    Oct 1, 2015 at 20:34
  • $\begingroup$ @chris yes, please. $\endgroup$
    – rcollyer
    Oct 1, 2015 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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