1
$\begingroup$

When using manipulate and plotting a function within an IF statement, curly brackets appear in the panle with the displayed plot. Here is a simple version of the issue. Can someone tell how to suppress the brackets? Thanks!

Manipulate[
 stable = True;
 If[stable,
  {
   p1 = Plot[Sin[\[Alpha] u], {u, 0, 2 Pi}, ImageSize -> Medium, PlotStyle -> Blue];
   p2 = Plot[Sin[\[Beta] u], {u, 0, 2 Pi}, ImageSize -> Medium, PlotStyle -> Red];
   Show[{p1, p2}]
   },
  {
   p3 = Plot[Cos[\[Alpha] u], {u, 0, 2 Pi}, ImageSize -> Medium];
   p4 = Plot[Cos[\[Beta] u], {u, 0, 2 Pi}, ImageSize -> Medium];
   Show[{p3, p4}]
   }],
 (* Define parameters and create sliders *)
 Style["Testing Plots within IF Statement ", Bold, 20],
 Delimiter, Style["Parameters", Bold, 14], {{\[Alpha], 1, Style["Frequency 1", 12]}, 1, 10, 1, 
  Appearance -> "Labeled", BaseStyle -> FontSize -> 12}, {{\[Beta], 2, Style["Frequency 2", 12]}, 1, 
10, 1, Appearance -> "Labeled", BaseStyle -> FontSize -> 12},

 TrackedSymbols :> {\[Alpha], \[Beta]}, SynchronousUpdating -> False, 
 ControlType -> Slider, ControlPlacement -> Left]

Output

$\endgroup$

1 Answer 1

3
$\begingroup$

curly brackets appear in the panle with the displayed plot

Well, this is because you had them there. There is no need for them. You had this

 If[stable,{..; ;..},{..; ;..}]

You can just used

 If[stable,..;..;..,..;...]

I also removed the {} inside Show. Not needed. i.e. replace

 Show[{p3, p4}]

with just

  Show[p3, p4]

And it still works.

Mathematica graphics

Manipulate[stable = True;
 If[stable,
  p1 = Plot[Sin[α u], {u, 0, 2 Pi}, ImageSize -> Medium, PlotStyle -> Blue];
  p2 = Plot[Sin[β u], {u, 0, 2 Pi}, ImageSize -> Medium, PlotStyle -> Red];
  Show[p1, p2]
  ,      
  p3 = Plot[Cos[α u], {u, 0, 2 Pi}, ImageSize -> Medium];
  p4 = Plot[Cos[β u], {u, 0, 2 Pi}, ImageSize -> Medium];
  Show[p3, p4]
  ]
 ,

 (*Define parameters and create sliders*)
 Style["Testing Plots within IF Statement ", Bold, 20], Delimiter, 
 Style["Parameters", Bold, 14],{{α, 1, Style["Frequency 1", 12]}, 1, 10, 1, 
  Appearance -> "Labeled", BaseStyle -> FontSize -> 12},
 {{β, 2, Style["Frequency 2", 12]}, 1, 10, 1, 
  Appearance -> "Labeled", BaseStyle -> FontSize -> 12},
 TrackedSymbols :> {α, β},
 SynchronousUpdating -> False,
 ControlType -> Slider, ControlPlacement -> Left
 ]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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