# What is the syntax to conditionally suppress plotting in version 9?

Bug introduced in 9.0 and fixed in 9.0.1

In Mathematica 7 it is very easy to conditionally suppress plotting of individual lines using If:

Plot[{
If[x^2 < 2, x^2],
If[Exp[x] > x^2, Exp[x]],
If[False, x]                (* check recommended by Rahul *)
},
{x, -2, 2},
PlotStyle -> Thick, Frame -> True]


Or more verbosely using Piecewise and Indeterminate:

Plot[{
Piecewise[{{x^2, x^2 < 2}}, Indeterminate],
Piecewise[{{Exp[x], Exp[x] > x^2}}, Indeterminate],
Piecewise[{{x, False}}, Indeterminate]      (* check recommended by Rahul *)
},
{x, -2, 2},
PlotStyle -> Thick, Frame -> True]


It is reported that neither method works in version 9.0.0 (at least on OSX.) Furthermore it is reported that my attempt using ConditionalExpression also fails:

Plot[{
ConditionalExpression[x^2, x^2 < 2],
ConditionalExpression[Exp[x], Exp[x] > x^2]
},
{x, -2, 2},
PlotStyle -> Thick, Frame -> True]


Plotting a zero is reported to "work" but that is hardly a solution:

Plot[{
Piecewise[{{x^2, x^2 < 2}}],
Piecewise[{{Exp[x], Exp[x] > x^2}}]
},
{x, -2, 2},
PlotStyle -> Thick, Frame -> True]


1. Is this indeed a bug in version 9.0.0?

2. Is there a workaround for the affected systems?

• It seems to work unless I missed something. – Szabolcs May 16 '14 at 17:32
• @Szabolcs Which version are you using? A recent comment indicates this may be a bug in version 9.0.0. – Mr.Wizard May 16 '14 at 17:34
• @Szabolcs I agree - it works for me on OSX and version 9.0.1. – Jens May 16 '14 at 17:34
• @Mr.Wizard I'm using 9.0.1 (from the version string it's not very clear but 9.0.0 was released in November, and 9.0.1 in January). 9.0.0 had lots of bugs and I think no one should be using it ... there are many examples of bugs fixed in 9.0.1 on this site. – Szabolcs May 16 '14 at 17:36
• Going by Jens's and Szabolcs's comments it does seem like a bug that was fixed in 9.0.1 then. I didn't know 9.0.0 was so well known to be bug-ridden. – Rahul May 16 '14 at 17:54

Since this bug seems to be tied directly to the appearance of Indeterminate as the only available function value in the plot range, it could perhaps be considered a work-around to replace Indeterminate by another "quantity" that behaves the same way as Indeterminate but doesn't cause the whole display of all other functions to be suppressed.

I tried the following, and it works on version 9.0.0:

Plot[{Piecewise[{{x^2,x^2<2}},Indeterminate],
Piecewise[{{Exp[x],Exp[x]>x^2}},Indeterminate],
Piecewise[{{x,False}},I]      (*modified check recommended by Rahul*)},
{x,-2,2},
PlotStyle->Thick,Frame->True]


Here, I used the imaginary unit I to produce the same effect as Indeterminate, and the remaining plots do still get displayed.

To make this more general, maybe one can use a replacement rule like this:

Plot[Evaluate[{Piecewise[{{x^2, x^2 < 2}}, Indeterminate],
Piecewise[{{Exp[x], Exp[x] > x^2}}, Indeterminate],
Piecewise[{{x, False}},
Indeterminate]      (*modified check recommended by Rahul*)} /.
Indeterminate -> I], {x, -2, 2}, PlotStyle -> Thick, Frame -> True]


In my Version 9.0 for Microsoft Windows (64-bit) (November 20, 2012) Release ID 9.0.0.0 (3868239, 384640), Patch level 0,

Plot[{ConditionalExpression[x^2,x^2<2],ConditionalExpression[Exp[x],Exp[x]>x^2]},{x,-2,2},PlotStyle->Thick,Frame->True]


works normally, but neither

Plot[{If[x^2<2,x^2],If[Exp[x]>x^2,Exp[x]],If[False,x]                (*check recommended by Rahul*)},{x,-2,2},PlotStyle->Thick,Frame->True]


nor

Plot[{Piecewise[{{x^2,x^2<2}},Indeterminate],Piecewise[{{Exp[x],Exp[x]>x^2}},Indeterminate],Piecewise[{{x,False}},Indeterminate]      (*check recommended by Rahul*)},{x,-2,2},PlotStyle->Thick,Frame->True]


do : only a frame for x=-2 to +2 and y from -1 to +1 get plotted (with x=0 and y=0 line).
Does that make sense?