Hot answers tagged

12

1. You can use HorizontalGauge as a control in Manipulate: Manipulate[Plot[Sin[x + phi], {x, 0, 2 Pi}], {phi, 0, 2 Pi, Panel[HorizontalGauge[##, ScaleDivisions -> None, Axes -> {True, False}, ImageSize -> 250, Ticks -> {Transpose[{Subdivide[8], Subdivide[0, 2 Pi, 8]}], None}], #, Right] &}] To allow only discrete values, say ...


11

This should give you a starting point: opt = {PlotStyle -> Orange, AxesLabel -> {"\[Mu]s", "V"}, ImageSize -> 300} Manipulate[ Plot[Sin[10/x], {x, 0, 5}, PlotRange -> {xInt, {vMin, vMax}}, Evaluate[opt]], {{vMax, 0}, -1, 1, VerticalSlider, Appearance -> "Labeled"}, {{vMin, -1}, -1, 1, VerticalSlider, Appearance -> "Labeled"}, {{xInt,...


10

Reanalysis My earlier assertions were incorrect or at least incomplete. I now believe the problem in your code originates because of a particular behavior that can be seen in this separate example: asc = <|foo -> <|bar -> <|baz -> 1|>|>|> <|foo -> <|bar -> <|baz -> 1|>|>|> asc[foo][bar][baz] = 2; asc ...


9

Two, now three, ways: I think I'd recommend the first -- strike that -- maybe the third one at the end, but perhaps you have a reason for using SetPrecision, in which case, use the second. This first one works as is. One caveat: if the label is used as an input field, the number k will be set to a machine-precision number. Manipulate[ Plot[Cos[k x], {x, ...


9

is this what you mean? ClearAll[r, a, b, d]; potentialsurface = 1/r^12 - 2/r^6 + 1/d^12 - 2/d^6 - (2 Exp[-(r - d)] + 2 Exp[-(d - r)] - 2 Exp[-(2 (r - d) - 2 (d - r))*Cos[d]]); Manipulate[ Module[{z}, z = N[1/a^12 - 2/a^6 + 1/b^12 - 2/b^6 - (2 Exp[-(a - b)] + 2 Exp[-(b - a)] - 2 Exp[-(2 (a - b) - 2 (b - a))*Cos[b]])]; Grid[{{...


8

Because I'm new to Mathematica, I thought it may be helpful to newer people to answer this question the way a "new user" may think about the problem without the use of the more compact symbols. Obviously, MichaelE2 has covered the gambit of options already, and the solution below is negligibly different from his "non-editable label" solution. To create the ...


8

Here is the example from TrackingFunction: Manipulate[x, {{x, 2}, 0, 100, 1, TrackingFunction -> (If[PrimeQ[#], x = #] &)}]


7

Keep slider linear and have another variable. Manipulate[ DynamicModule[{p = Prime[n]}, p], {n, 1, 10, 1, Appearance -> "Labeled"}] Or, specify a setter bar but then force slider. With[{k = 10}, Manipulate[n, {n, Prime /@ Range[k], ControlType -> Slider}]] Or, make a custom interactive structure without Manipulate. With[{k = 10}, ...


7

You can achieve this by using both Dynamic and Slider: {Slider[Dynamic[x], {list}], Dynamic[x]}


7

You can tweak underlying Graphics: IntervalSlider[ Appearance -> {"ThumbAppearance" -> {Style["[", 18], None, Style["1000", 18]}} , BaseStyle -> { GraphicsBoxOptions -> { PlotRangePadding -> {{.1, .1}, Automatic} } } ]


6

Another approach is to use Manipulate. It is designed to handle the problem you have presented and takes care of all that Dynamic stuff internally. Manipulate[ Plot[m/2 + Sum[ (2*m/(n*Pi)^2)*((-1)^n - 1)*(Cos[n*Pi*x/m]), {n, 3} ], {x, -m, m} ], {{m, 1}, 0.1, 5.0, Appearance -> "Labeled"} ]


6

Example DynamicModule[ {value = 10}, Panel @ Row @ { Slider[Dynamic @ value, {1, 100, 1}, ImageSize -> Small], InputField[Dynamic @ value, Enabled -> False, ImageSize -> {36, 18}], Button["-", value--], Button["+", value++] } ] Output EDIT In order to restrict Slider to a set of pre-defined values, please see ...


6

I do this all the time, but use small buttons next to the slider. This is handy when one wants to jump to specific value, and sometimes it is hard to get the slider to go there exactly without few hits and misses and one ends up opening the slider using "+" and typing in the value in the small window which is not very efficient sometimes. Here is an example ...


6

You will need work with an interval slider in terms of AbsoluteTime values because such sliders only work with numeric objects. Here is a demonstration where a interval slider has the behavior you want. With[{ min0 = AbsoluteTime @ DateObject[{2015, 3, 8, 10, 0, 0.}], max0 = AbsoluteTime @ DateObject[{2015, 3, 8, 12, 30, 0.}], minT = AbsoluteTime @ ...


6

Example Manipulate[ i, {i, {0, 1, 2.22, 5, 141, 299}, Slider} ] Output Reference Manipulate


6

It seems like a bug. Here's fix, via explicitly constructing the slider (Manipulator): n =.; DynamicModule[{c, t, main, f}, Manipulate[ ControlActive[{x, y}, main[x, y]], {{x, c/2, "n1"}, 1, y - c, 1}, {{y, n - c/2, "n2"}, x + c, n, 1, Manipulator[#1, {x + c, n, 1}] &}, SynchronousUpdating -> False, Initialization :> ( n = 300; ...


6

DynamicModule[ { pt1, pt2, dist , trackingFunction = Function[{val, sym} , If[Block[{sym = val}, dist >= 2], sym = val] , HoldRest ] } , Manipulate[ Graphics[{Point[Dynamic@pt1], Point[Dynamic@pt2]} , PlotRange -> 5, Frame -> True ] , {{x1, 0}, -5, 5, TrackingFunction :> trackingFunction} , {{y1, 0}, -5, 5, ...


6

You can also wrap the interval slider object with Style and use DefaultOptions to set PlotRangePaddding option values: s = IntervalSlider[Appearance -> {"ThumbAppearance" -> {Style["[", 18], None, Style["1000", 18]}}] Style[#, DefaultOptions -> {Graphics -> PlotRangePadding -> {{Automatic, .1}, Automatic}}] & @ s


5

It could be as simple as this: Manipulate[ DateString[t], {t, DateObject[{2015, 1, 1, 12, 0}], DateObject[{2015, 1, 1, 22, 30}], Quantity[5, "Minutes"]}] Using DateObjects rather than a List to indicate a date & time seems to work.


5

Based on the documentation, Slider is the only control object used in your code that supports a list of expression as its settings. Here is a custom alternative. DynamicModule[{list = {0.001, 0.0025, 0.005, 0.006, 0.007, 0.008, 0.009, 0.01}, l}, Row[{ Slider[Dynamic@l, {list}], Spacer[5], InputField[Dynamic[l, If[MemberQ[list, #], l = #] &], ...


5

How about using a different object to control some variables? It's not exactly a Manipulate control but it can have the same effect: HorizontalGauge[Dynamic@{x, y, z}, {0, 100}] I haven't worked out the constraining of variables but this could be a useful start.


5

dtpts1a = Table[RandomInteger[{1,100}],{i,128},{j,2}]; Manipulate[ MapAt[n*#&, dtpts1a, {All,2}] ,{n,0,1}] EDIT By default Manipulate uses steps of 10^-3 * rangeMax for the variable. You can decrease the step size and use SetAccuracy to always show four digits Manipulate[ SetAccuracy[MapAt[n*#&, dtpts1a, {All,2}],5] ,{n,0,1,0.0001}]


4

You mean something like this? Manipulate[ Plot[Cos[k x], {x, 0, 2 Pi}, Frame -> True, Axes -> False, ImagePadding -> 30], Text[Style[ Grid[{ {Style["k", Italic], Spacer[2], Manipulator[Dynamic[k, {k = SetPrecision[#, 22]} &], {0, to, del}, ImageSize -> Tiny], Spacer[2], Dynamic[AccountingForm[k , (*choose ...


4

Simply use the wrapper Style[ expr , ControlsRendering -> "Generic" ] or as has been stated in the comments use the option BaseStyle: Style[ Manipulate[ Null, {{a,1},1,10,1} ], ControlsRendering -> "Generic" ]


4

m = 1; Slider[Dynamic[m]] Dynamic[ Plot[ m/2 + Sum[ (2*m/(n*Pi)^2)*((-1)^n - 1)*(Cos[n*Pi*x/m]) , {n, 3}] , {x, -m, m} ] ] EDIT Follow @Amir's comments and read the documentation for Dynamic


4

use ImageSize on the slider. For example Manipulate[{a, b, c}, {{a, 1, "a"}, .1, 1, .1, ImageSize -> Large}, {{b, 1, "b"}, .1, 1, .1, ImageSize -> Tiny}, {{c, 1, "c"}, .1, 1, .1, ImageSize -> Small} ]


4

You can specify exactly what you want using controls. Have a look at the Introduction to Control Objects tutorial. Manipulate[x, Row[{ Slider[Dynamic@x, {-100, 100, 0.001}], Button["\[LessLess]", x = Max[x - 0.01, -100]], Button["<", x = Max[x - 0.001, -100]], Button[">", x = Min[x + 0.001, 100]], Button["\[GreaterGreater]", x = Min[x +...


4

The problem is with Animator. When it is passed a list, the +/- buttons increment the index of the setting by about 5-10%. It seems to pick a "nice" increment that is 1, 2 or 5 times a power of 10. When the length of the list is less than 10, it does not behave well. It seems that an increment of 0 is what is sometimes calculated. (Personally, I would ...


4

A teeny modification to Smit's solution, to fit the requirements of the question: With[{lower = 0, higher = 1}, Column[ {HorizontalGauge[Dynamic[{x, y, z}, Function[{val}, {x, y, z} = Sort[val]]], {lower, higher}, ImageSize -> 400], Dynamic[{x, y, z}]}] ]


4

So to expand a little on my comment, to make a slider be greyed out you can use Enabled: Manipulate[ Plot[a t^2 - b t, {t, -1, 1}, Frame -> True, PlotRange -> {{-1, 1}, {-1, 1}}], {{a, 1, Style["Parameter 1", 10]}, -10, 10, 0.01}, {{b, 1, Style["Parameter 2", 10]}, -10, 10, 0.01, Enabled -> False} ] From the tutorial ...


Only top voted, non community-wiki answers of a minimum length are eligible