# Manipulating several values from the same interval

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?

• 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

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}]}];


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.

• 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}] 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}] 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]
] &}
] 