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.

Some of my calculations depend on the choice of several values from the interval [-2, 2] (it is more or less interpolation of a fixed function using the points as parameters). I want to create a dynamic control for them. The ideal thing to have would be a Slider with multiple positions to move, or a Locator on a line. As for now, I have tried to implement the second variant:

Manipulate[
  points[[All, 2]] = Table[0, {5}];
  Plot[points, {x, -2, 2}, PlotRange -> 1/100, AspectRatio -> 0.01],
  {{points, ({#, 0} &) /@ RandomReal[{-2, 2}, {5}] }, Locator}]

That works, but with quirks: locator panes still can be lifted visibly higher or lower than the base line. Sure, they fall back immediately due to points[[All, 2]] = Table[0, {5}] line, but I hope there is a better solution. Is there?

share|improve this question
    
See 1), 2), 3), 4), 5). Almost an exact duplicate, but this admits a solution the others do not. –  Michael E2 Jun 17 '13 at 23:32

2 Answers 2

up vote 2 down vote accepted

Simple fix: if you set the option

AspectRatio -> 10^-10

then it's impossible to see the slight jiggling of the locators as you move them with the mouse. You can also make it look like anything you wish. For instance, if you want it to be ugly, you can define

g = Graphics[{Red, PointSize[Large], Point[{0, 0}]}];

and then add

Appearance -> g

to your Locator definition. In this way, you can "build" the multi-slider you are asking for. if you are good with graphics, you could even make it look just like a slider.

share|improve this answer
    
Yeah, that's better, but I still hope for the more "conceptual" way to make a manipulator for several variables from the same interval. –  Dmitry Jun 17 '13 at 19:17
    
Well, it seems there is no radically better solution. Thank you. –  Dmitry Jun 17 '13 at 19:32

Here's a quite natural way built into Manipulate and LocatorPane. Use the two arguments ...{-2., 0.}, {2., 0.},... below to set the domain for the Locators. This lets the x coordinate range from -2 to 2 and the y coordinate range from 0 to, well, 0 -- that is, it can't move vertically.

Manipulate[
 Plot[Evaluate[Times @@ (x - First /@ points)], {x, -2, 2}, 
  PlotRange -> {{-2, 2}, {-1, 1}}],
 {{points, ({#, 0} &) /@ RandomReal[{-2, 2}, {5}]}, {-2., 0.}, {2., 0.}, Locator}]

Manipulate

Here's another way. Use a LocatorPane and the second argument to Dynamic to set all of the second coordinates to 0. Here I have put a little grid above the Locator graphic to show the x, y coordinates. Of course the grid could be anything. So this example shows how to integrate ths sort of Locator control into Manipulate.

Manipulate[
 Column[{
   Dynamic @ Grid @ Transpose @ points, 
   LocatorPane[Dynamic[points, (points = {#, 0} & /@ First /@ #) &],
    Graphics[{}, PlotRange -> {{-2, 2}, {-.1, .1}}, Axes -> True, 
     ImageSize -> 300, Ticks -> {Automatic, None}]
    ]
   }],
 {{points, ({#, 0} &) /@ RandomReal[{-2, 2}, {5}]}, ControlType -> None}]

Another Manipulate


Edit:

Here's a variation on the preceding Manipulate in which the Locator control appears in the control area. This is perhaps a more natural way to incorporate a "multi-slider."

Manipulate[
 Column[{
   Dynamic @ Grid @ Map[Pane[#, {60, 12}] &, Transpose@points, {2}]
   }],
 {{points, ({#, 0} &) /@ Round[RandomReal[{-2, 2}, {5}], .001]}, 
   LocatorPane[Dynamic[points, (points = {#, 0} & /@ First /@ #) &],
     Graphics[{}, PlotRange -> {{-2, 2}, {-.1, .1}}, Axes -> True, 
       ImageSize -> 300, Ticks -> {Automatic, None}],
     Appearance -> Graphics[{EdgeForm[Gray], LightGray, Disk[]}, ImageSize -> 10]
     ] &}
 ]

Manipulate with multi-slider control

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.