5
$\begingroup$

The code below is something I wrote quickly to simulate the problem I'm having with more complex code. I use Row (or Grid) to get the first 2 manipulate variables (a and b) on one line above the plot and I want the other 2 variables (c and d) in one line below the plot. I can get the controls where I want them without Row (or Grid) but then they appear in a column. Whenever I add Row all controls appear to have the same placement. I wasn't able to find any other posts that could help me with this problem.

Manipulate[
 f = a*x^3 + b*x^2 + c*x + d;
 Plot[f, {x, -4, 4}],
 Row[{
   Control[{{a, 1, "a"}, 0, 3, ControlPlacement -> Top}],
   Control[{{b, 2, "b"}, 0, 5, ControlPlacement -> Top}]
   }],
 Row[{
   Control[{{c, 1, "c"}, 0, 4, ControlPlacement -> Bottom}],
   Control[{{d, 0, "d"}, 0, 2, ControlPlacement -> Bottom}]
   }]
 ]

enter image description here

$\endgroup$
1
  • 3
    $\begingroup$ You can get more flexibility in positioning if you use a DynamicModule and build up the grid and control elements. $\endgroup$
    – rm -rf
    Mar 6, 2014 at 5:20

2 Answers 2

10
$\begingroup$

That is how you might do it within the framework of Manipulate:

    Manipulate[
 Plot[a*x^3 + b*x^2 + c*x + d, {x, -4, 4}], 
 Row[{Control[{{a, 1, "a"}, 0, 3}], Spacer[20], Control[{{b, 2, "b"}, 0, 5}]}], 
 Row[{Control[{{c, 1, "c"}, 0, 4}], Spacer[20], Control[{{d, 0, "d"}, 0, 2}]}],
 ControlPlacement -> {Top, Top, Bottom, Bottom}
              ]

It looks as follows:enter image description here Have fun.

$\endgroup$
3
  • $\begingroup$ Thank you! I don't understand how I didn't even think of this. $\endgroup$
    – baumannr
    Mar 7, 2014 at 0:37
  • $\begingroup$ This code is like a little miracle. $\endgroup$
    – User18
    Jun 20, 2018 at 3:23
  • $\begingroup$ However, there is something strange in the result! Here, controls a and b are at the bottom, whereas controls c and d are at the top! And after some trial and error I have found that ControlPlacement -> {Top, Bottom} works, where it seems that Top points to the first row and Bottom to the second. $\endgroup$
    – User18
    Jun 20, 2018 at 13:39
3
$\begingroup$

Illustrating the advice of rm-rf:

DynamicModule[
 {f, a, b, c, d},
 f = a*x^3 + b*x^2 + c*x + d;
 Column[
  {Row[{"a  ", Slider[Dynamic[a], {0, 3}], "b  ", 
     Slider[Dynamic[b], {0, 3}]}, Frame -> True],
   Dynamic@
    Plot[f, {x, -4, 4}, ImageSize -> 400, PlotRange -> {-50, 50}, 
     PlotStyle -> {Red, Thick}, 
     PlotLabel -> 
      Row[{Style["f(x)=", 20], Style[TraditionalForm[f], 20]}]],
   Row[{"c  " Slider[Dynamic[c], {0, 3}], "d  ", 
     Slider[Dynamic[d], {0, 3}]}, Frame -> True]}, Frame -> True
  , Background -> LightYellow]]

I am sorry for not using some parameter ranges, but aim was illustrative:

enter image description here

$\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.