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}}]
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}}]
Question
Am I missing something obvious?
Answer
The cause is your data is out of order. So, the workaround is
ListLinePlot[SortBy[First] /@ dat, PlotStyle -> Red,
Filling -> {1 -> {2}}]
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.
Comments
Post a Comment