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.

I'd like to have a checkbox in a Manipulate expression, governing whether part of the graphics is displayed or not. For instance, assume that I have a surface with two planes:

Show[Plot3D[x^2+y^2,{x,-1,1},{y,-1,1},PlotStyle->Opacity[0.5]],
  ParametricPlot3D[{0, u, v}, {u, -1, 1}, {v, -1, 1}, PlotStyle -> Opacity[0.5], Mesh -> None],
  ParametricPlot3D[{u, 0, v}, {u, -1, 1}, {v, -1, 1}, PlotStyle -> Opacity[0.5], Mesh -> None]]

Now I'd like to wrap it in a Manipulate with two checkboxes, enabling or disabling the planes. Currently, I'm doing something like this:

Manipulate[
 Apply[Show, 
  Join[{Plot3D[...]}, 
   If[xzero, {ParametricPlot3D[{0, u, v}, {u, -1, 1}, {v, -1, 1}, 
      PlotStyle -> Opacity[0.5], Mesh -> None]}, {}], 
   If[yzero, {ParametricPlot3D[{u, 0, v}, {u, -1, 1}, {v, -1, 1}, 
      PlotStyle -> Opacity[0.5], Mesh -> None]}, {}]]],
{{xzero, True, "x=0"}, {True, False}}, {{yzero, True, "y=0"}, {True, 
   False}}]

but somehow feel it's overly complicated. What is the right way to do this?

share|improve this question

2 Answers 2

p1 = ParametricPlot3D[{0, u, v}, {u, -1, 1}, {v, -1, 1}, 
                       PlotStyle -> Opacity[0.5], Mesh -> None];
p2 = ParametricPlot3D[{u, 0, v}, {u, -1, 1}, {v, -1, 1}, 
                       PlotStyle -> Opacity[0.5], Mesh -> None];

Manipulate[Show[
          Plot3D[x x + y y, {x, -1, 1}, {y, -1, 1}],
          If[xzero, p1, Sequence @@ {}], If[yzero, p2, Sequence @@ {}]],
         {{xzero, True, "x=0"}, {True, False}}, 
         {{yzero, True, "y=0"}, {True, False}}]

Mathematica graphics

share|improve this answer

Discrete control via opacity:

Manipulate[
  Show[Plot3D[x^2 + y^2, {x, -1, 1}, {y, -1, 1},   PlotStyle -> Opacity[0.5]], 
  ParametricPlot3D[{0, u, v}, {u, -1, 1}, {v, -1, 1}, 
  PlotStyle -> Opacity[xzero], Mesh -> None], 
  ParametricPlot3D[{u, 0, v}, {u, -1, 1}, {v, -1, 1}, PlotStyle -> Opacity[yzero], 
  Mesh -> None], AxesLabel -> {X, Y, Z}],
 {{xzero, .5, "x=0"}, {0, .5}, Checkbox},
 {{yzero, .5, "y=0"}, {0, .5}, Checkbox},ControlPlacement -> Left]

enter image description here

But I usually prefer to control opacity continuously. Then you have more flexible control to "pronounce" one object and "denounce" another, still keeping it. If opacity is set to zero - plane disappear.

Manipulate[
 Show[Plot3D[x^2 + y^2, {x, -1, 1}, {y, -1, 1}, 
   PlotStyle -> Opacity[0.5], Mesh -> True, MeshFunctions -> {#3 &}, 
   ColorFunction -> "Rainbow"], 
  ParametricPlot3D[{0, u, v}, {u, -1, 1}, {v, -1, 1}, PlotStyle -> 
    Directive[col1, Specularity[White, 30], Opacity[xzero]], Mesh -> None], 
  ParametricPlot3D[{u, 0, v}, {u, -1, 1}, {v, -1, 1}, PlotStyle -> 
    Directive[col2, Specularity[White, 30], Opacity[xzero]], 
   Mesh -> None], AxesLabel -> {X, Y, Z}],
 {{xzero, .5, "x=0"}, 0, 1, Slider, ImageSize -> 75},
 {{yzero, .5, "y=0"}, 0, 1, Slider, ImageSize -> 75},
 {col1, Blue, ImageSize -> Tiny},
 {col2, Red, ImageSize -> Tiny},
 ControlPlacement -> Left]

enter image description here

share|improve this answer

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.