8
$\begingroup$

This question is an exact duplicate of:

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.

$\endgroup$

marked as duplicate by Mr.Wizard Feb 8 '17 at 8:36

This question was marked as an exact duplicate of an existing question.

7
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Why is it needed at all? $\endgroup$ – BlacKow Jun 22 '15 at 19:52
  • $\begingroup$ @BlacKow - see edit above. $\endgroup$ – Bob Hanlon Jun 22 '15 at 22:47
  • $\begingroup$ That's terribly disappointing as I have favored Evaluated -> True for years because it preserves localization of the plot variable. We must wrap the entire thing in Block[{x}, . . . ] in this case now to handle it properly. Nevertheless +1. $\endgroup$ – Mr.Wizard Jun 23 '15 at 9:47

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