8

I used a code very similar to the code posted by Kuba stacked line graph with fragmented data

TestData = {{{1, 23}, {4, 3}, {10, 34}, {12, 34}, {20, 5}}, {{5, 
     3}, {6, 3}, {7, 4}, {15, 12}, {21, 5}}};
Plot[Piecewise[{{Interpolation[#, x, 
         InterpolationOrder -> 0], #[[1, 1]] <= x <= #[[-1, 1]]}, {#[[
         1, 2]], x < #[[1, 1]]}, {#[[-1, 2]], x > #[[-1, 1]]}}] & /@ 
    TestData // Accumulate // Reverse, {x, 0, 25}, 
 AxesOrigin -> {0, 0}, Frame -> True, 
 Filling -> {1 -> Axis, 2 -> {1}}, FillingStyle -> {Red, Blue}, 
 Evaluated -> True, PlotStyle -> Thick, Frame -> True, 
 BaseStyle -> {18, Bold}, PlotRange -> All]

Using v.9.0 I get the desired output: Output v.9.0

If a execute the same code in v.10.1 the filling looks different. Output v.10.1

What change between v.9 and v.10 is responsible for the different behaviour? Couldn't find a way to get the same output as in v.9.0 until now.

RMMA
  • 2,710
  • 2
  • 18
  • 33

1 Answers1

7

Use Evaluate[...] rather than Evaluated -> True

START EDIT:

Attributes[Plot]

{HoldAll, Protected, ReadProtected}

Since Plot has the attribute HoldAll the first expression is initially interpretted as a single entity. To make the argument a list of two distinct entities it must be evaluated to override the HoldAll attribute. Evaluated is not a documented option for Plot and apparaently does not work in this case in version 10.1. Whereas, use of Evaluate is documented in the documentaton for Plot: "- Plot has attribute HoldAll and evaluates f only after assigning specific numerical values to x. - In some cases, it may be more efficient to use Evaluate to evaluate f symbolically before specific numerical values are assigned to x."

END EDIT.

$Version

"10.1.0 for Mac OS X x86 (64-bit) (March 24, 2015)"

TestData = {{{1, 23}, {4, 3}, {10, 34}, {12, 34}, {20, 5}}, {{5, 3}, {6, 
     3}, {7, 4}, {15, 12}, {21, 5}}};
Plot[Evaluate[
  Piecewise[{{Interpolation[#, x, InterpolationOrder -> 0], #[[1, 1]] <= 
          x <= #[[-1, 1]]}, {#[[1, 2]], x < #[[1, 1]]}, {#[[-1, 2]], 
         x > #[[-1, 1]]}}] & /@ TestData // Accumulate // Reverse], {x, 0, 
  25}, AxesOrigin -> {0, 0}, Frame -> True, Filling -> {1 -> Axis, 2 -> {1}}, 
 FillingStyle -> {Red, Blue}, PlotStyle -> Thick, Frame -> True, 
 BaseStyle -> {18, Bold}, PlotRange -> All]

enter image description here

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198