Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.
ListPlot[{{{1, 0}, {0, 0.5}}, {{1, 1}, {0, 1}}}, Filling -> {1 -> {2}}, 
 FillingStyle -> LightGray, Joined -> True, Frame -> True]

Mathematica graphics

Results in no filling, whereas...

ListPlot[{{{0, 0}, {1, 0.5}}, {{0, 1}, {1, 1}}}, Filling -> {1 -> {2}}, 
 FillingStyle -> LightGray, Joined -> True, Frame -> True]

gives the expected fill.

Why does the order matter or more literally is this expected behavior and if so why?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Sort the data

ListPlot[Sort /@
  {{{1, 0}, {0, 0.5}}, {{1, 1}, {0, 1}}},
 Filling -> {1 -> {2}},
 FillingStyle -> LightGray,
 Joined -> True,
 Frame -> True]

enter image description here

share|improve this answer
1  
That certainly works but don't you think its a bit odd it doesn't work without the Sort? –  Ymareth Aug 27 at 15:12
    
Sort is required because Mma does not know whether you intend the data to be ordered. For example, How would the following be filled? ListPlot[{{{1, 0}, {0, 0.5}, {.5, .75}}, {{1, 1}, {2, .25}, {0, 1}}}, Joined -> True, Frame -> True] –  Bob Hanlon Aug 27 at 15:28
    
I agree your example is ambiguous but mine is not, interpolation between their points in x is not multivalued and the space between the lines is well defined. –  Ymareth Aug 27 at 15:50
    
Presumably the only prior analysis done is to check whether the data is ordered. Your data isn't. OrderedQ /@ {{{1, 0}, {0, 0.5}}, {{1, 1}, {0, 1}}} gives {False, False}. –  Bob Hanlon Aug 27 at 16:05
    
Fair point. I guess I'm assuming that internally some kind of interpolation function is being built and the intersection of support for both objects is constructed. My assumption is most likely wrong because of the counter-cases, like yours, where its not obvious what to do. I'll accept your answer. –  Ymareth Aug 27 at 16:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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