Hot answers tagged

20

Presumably your Notebooks are not being saved in a Trusted Path. Start by reading the tutorial Notebook Security, and note: If the notebook's directory is trusted, the notebook will be allowed to automatically perform dynamic evaluations without alerting the user. If the notebook's directory is untrusted, the user will be alerted upon any attempt by the ...


14

Here is a slight modernization of old code by Stan Wagon for generating epicycles, based on this paper by Frank Farris: Options[EpicyclePlot] = {AnimationRunning -> True, ColorFunction -> Automatic, "Frames" -> 16, "Movie" -> True, "MovieTimeInterval" -> Automatic, PlotPoints -> 100, "ShowWheels" -> True}; EpicyclePlot[{radii_, ...


12

Update 2: Using DynamicSetting to turn Manipulate into an input expression to print snapshots: manipulate = Manipulate[Module[{a = {{2, 3}, {3, 2}}, vp}, vp = VectorPlot[a.{x, y}, {x, -4, 4}, {y, -4, 4}, VectorScale -> {0.045, 0.9, None}, VectorPoints -> 16]; z = NDSolveValue[Thread[{x'[t], y'[t], x[0], y[0]} == Join[a.{x@t, ...


12

The basic idea is fairly simple: GraphicsComplex[ ReIm@Accumulate[epicycle @@ data], {Point@Range[n + 1], Line@Range[n + 1], MapThread[Circle, {Range[n], data[[1]]}] }] In the above epicycle computes each epicycle, in essentially the same way as ubpdqn as complex numbers, which are then added together with Accumulate; ReIm converts the complex ...


11

Just like Albert I recommend using the second argument of Dynamic. Furthermore I recommend that you embrace the first A in AJAX, which stands for "asynchronous", so the kernel isn't busy while it collects the data (this might be why some change events are lost with your code). You can see how well the second argument of Dynamic works with this example: ...


11

I believe you want "FrontFaceColor" which can be found as a specification in this list: Graphics[{FaceForm[RGBColor[2/3, 1/3, 2/3]], EdgeForm[Black], Dynamic[{If[CurrentValue["MouseOver"], Darker @ CurrentValue["FrontFaceColor"]], Disk[]}]}] You may also find "FrontFaceOpacity" of use. Simply guessing I found that "BackFaceColor" is also ...


11

I really think that other answers here are adequate, but since specific examples are being requested, here's one. f[x_] := memoize[x] memoize[x_]:=memoize[x]=x This is a function you want to call inside and outside of Dynamic. You want the caching effect, but you don't want Dynamic to go crazy on this. Which it will. Observe: In[139]:= Clear[memoize]; ...


11

Again I choose a dynamic module to implement your request. This time I don't use a locator, but take direct control of mouse events. With[{span = 10., viscosity = .01}, Framed @ DynamicModule[{mouseXY, xmin, xmax, ymin, ymax}, {xmin, xmax} = {ymin, ymax} = span {-1., 1.}/2.; EventHandler[ Dynamic @ Plot[span Sin[t]/2., ...


11

This is a direct copy-paste of @m_godberg's code, with a few minor changes to get rid of the viscosity parameter and allow the graphics to move precisely as much as the mouse was dragged. With[{span = 10.}, Framed @ DynamicModule[{mouseXY, xmin, xmax, ymin, ymax}, {xmin, xmax} = {ymin, ymax} = span {-1., 1.}/2.; EventHandler[ ...


10

This should work: SetSystemOptions["TypesetOptions" -> "ColorDirectiveSwatches" -> False]


10

Quick fix is to use e.g. Inactivate and friends: Manipulate[ Column[{ Activate @ #, Panel @ ExpressionCell[ # /. Inactive -> Defer, "Notebook", "Input" ] }] & @ Inactivate @ Plot[Sin[x], {x, -3, 3}, AxesLabel -> {xlabel, ylabel}, Ticks -> {tics, tics}] , Control[{{tics, Automatic, ""}, {Automatic ...


9

You can define a function that creates Manipulates with a "fake" SetterBar and a specific AutorunSequencing m[k_, seq_] := Manipulate[ Plot[{Sin[a*x] + b*Cos[3 a*x], k*x}, {x, 0, Pi}, ImageSize -> 400], {a, 1, 2}, {b, 0, 1}, Grid@{{"k", SetterBar[k, {0, .5, 1}]}}, AutorunSequencing -> seq, ContentSize -> {420, 270}] then create the frames ...


9

I think the standard way to do this is to use the second argument of Dynamic, e.g. like so: With[{ getCompletion = Function[ Import[ "https://maps.googleapis.com/maps/api/geocode/json", "JSON", "RequestParameters" -> {"address" -> #} ] //. {{r__Rule} :> (Association[r])} ]}, DynamicModule[{ addr = "555 Mission St, San ...


9

I think you are actually not doing anything wrong but have found one of those cases where the automatic dependency tracking doesn't work (I think this is a bug). You can make the code work (version 10.1 on Windows) by explicitly telling the last Dynamic to track choices: Dynamic[choices,TrackedSymbols:>{choices}] There are some things in your code ...


9

This is more like Dynamic: Clear[f] SetAttributes[f, HoldFirst] (*f[x_]:=g[x]*) Table[f[i], {i, 5}] (* {f[i], f[i], f[i], f[i], f[i]} *) By giving f a definition, it evaluated while in Table, during which the i got evaluated.


9

Update Inspired by @Craig, @MichaelE2 and @J.M. and integrating varying aspects (but without the polish of all the options): ep[{r_, a_, o_}, n_] := Module[{fun = Function[x, Accumulate@ Prepend[ReIm@MapThread[#1 Exp[I #2 x + I #3] &, {r, a, o}], {0, 0}]], col = RandomColor[Length@r], smin = Max[2 Pi/a], tab, g}, tab = ...


8

Using the "almost new" feature of NDSolve[] that allows it to detect vector equations based upon the dimensions of the initial conditions. a = {{2, 3}, {3, 2}}; vp = VectorPlot[a.{x, y}, {x, -4, 4}, {y, -4, 4}, Axes -> True, AxesLabel -> {x, y}, VectorScale -> {0.045, 0.9, None}, VectorPoints -> 16]; ...


8

I wrote something to do something a little like what you wanted. Here I've adapted it so you can get a run through for each setting of the SetterBar. Some description of the functions. autolist[control_pattern] := list of manipulate settings for the animation specs is a pattern for culling variable specifications out of a Manipulate ...


8

Response to edits: I don't know if I got all your points but this is the final update done by me :) v = {0.5, 0.05, 0.1, 0.15, 0.2}; active = Range@Length@v; update[i_, val_] := (v[[i]] = val; With[{range = DeleteCases[active, i]}, v[[range]] = (1 - val) Normalize[v[[range]], Total]]); updateCheckbox[i_, val_] := If[val, active = Join[active, ...


8

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; ...


8

Random test function I'm assuming all the functions to be considered are nonnegative, just as in the example. SeedRandom[0]; data = Transpose[{ Range[0., 1., 1./40], FoldList[ Max[0., Min[##]] &, Reverse@Sort@RandomReal[{-0.65, 1}, {41}] ] }]; f = Interpolation[data, InterpolationOrder -> 1]; Plot[f[x], {x, 0, 1}] ...


8

No, you only need the Internet connection if you are using Wolfram|Alpha to enter your inputs, because this is a web service. If you had typed the Mathematica input Plot[Sin[x]/x, {x, -9.4, 9.4}] rather than graph of sin[x]/x then this would not have happened. W|A's interpretation of inputs is unpredictable at the best of times, so I would suggest ...


8

As a Palette 1) Using ListLinePlot: CreatePalette[{ DynamicModule[{miu, timeStep = 0.1}, Grid[{ {Row[{"Current MemoryInUse [MiB]: ", Dynamic[Style[miu[[-1]], Bold], TrackedSymbols :> {miu}]}], Item[Row[{"time step: ", RadioButtonBar[Dynamic[timeStep], {0.1, 0.5, 1}], Spacer[35]}], Alignment -> Right]}, ...


8

This isn't a very elegant implementation, but since nobody else has answered so far, I've decided to post it. It is an extension of what I posted in this previous question. f1[x_] := x^2 f2[x_] := x + 1 With[{span = 10., δ = .1, f1DragPt = {0., f1[0.]}, f2DragPt = {0., f2[0.]}}, Framed @ DynamicModule[{mXY, action, xmin, xmax, ymin, ymax, p1, p2}, ...


7

This is just an idea how to prepare frames to export, don't have time for more now: f = Interpolation[ { {0, {1, 0, 0}}, {1, {2, 0, 0}}, {2, {2, 1, 0}}, {2.02, {1, 0, .5}}, {3, {1, 0, .5}}, {4, {2, 0, .5}}, {5, {2, 1, .5}}, {5.02, {1, 0, 1}}, {6, {1, 0, 1}}, {7, {2, 0, 1}}, {8, {2, 1, 1}} }, InterpolationOrder -> ...


7

I agree with Rojo's comments under his answer and I'd upvote them but the example from tutorials given in his answer is more confusing than educational for me (as expressed in comments). "For me", not "in my opinion" so maybe one can learn more from this part of tutorial. Nevertheless, I want to show you examples were using Refresh really matters. Refresh ...


7

With the arbitrary datasets datasets = {dataset1, dataset2, dataset3} = RandomReal[#, 100] & /@ {1, 2, 3}; one can pre-render the plots and add an empty plot for the case when no dataset is selected plots = Append[ MapThread[ListPlot[#1, Joined -> True, PlotStyle -> #2] &, {datasets, ColorData[97] /@ Range[3]}], ...


7

There are some doubts about using SaveDefinitions (1), (2), so let's implement brute force approach which may be used later automaticaly. Scheme Needs @ yourPackage (*a*) CDFDeploy[...]& @ With[{ source = (text content of the package, encoded or whatever) (*b*) }, DynamicModule[{ ... }, ... , Initialization:>( Get[#]& @ ...


7

An adaption of this answer for an ActionMenu and to your styling: assnMenuK[slowF_, a_Association, title_: "Choose"] := DynamicModule[{done = False, lastSelection = ""}, Grid[{{ ActionMenu[title, KeyValueMap[#2 :> (lastSelection = #2; done = "working"; slowF[#1]; done = True) &, a], Method -> "Queued"], ...


7

A simple example of one popup depending on the selection of another: DynamicModule[{x, y, list}, {PopupMenu[ Dynamic[x, (x = #; list = Switch[#, "A", {1, 2, 3}, "B", {4, 5, 6}, "C", {7, 8, 9}]; y = First[list]) &], {"A", "B", "C"}], Dynamic[PopupMenu[Dynamic[y], list], TrackedSymbols :> {list}]} ]



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