14
$\begingroup$

When I use manipulate, there is a 'plus sign' in the top right that, if I click on, shows my parameter value. I used animate, because other posts suggested that it solved other issues I had, but now there is no 'plus sign'. I'm sure I could add the value as text in the plot, but is there some OPTION that I can just set to include the 'plus sign'?

Here's my code, not that I think that it's useful for understanding my question:

f[x_] := x^2
a = 2;
Animate[Plot[{f[x], (f[a + h] - f[a])/h (x - a) + f[a]}, {x, -1, 9}, 
  PlotRange -> {{-1, 11}, {-1, 11}}], {{h, 2}, 0.000001, 2, 
  Appearance -> "Labeled"}, AnimationRunning -> False]
$\endgroup$
  • 2
    $\begingroup$ Hi! Why not post a minimal working example (preferably without fancy typesetting to make it easy to parse)? $\endgroup$ – Yves Klett Oct 30 '14 at 12:38
  • $\begingroup$ @Yves Really I don't think any code example at all is needed. The question is pretty straightforward without it unless there is a complication. $\endgroup$ – Mr.Wizard Oct 30 '14 at 12:39
  • $\begingroup$ @Mr.Wizard agreed. But I would prefer a MWE for asthetical reasons over the present code. But then your answer takes care of that. $\endgroup$ – Yves Klett Oct 30 '14 at 13:09
  • $\begingroup$ @Yves, thank you for the suggestion. I've attached a minimal example. $\endgroup$ – Joe Oct 30 '14 at 17:38
  • $\begingroup$ Appearance -> "Labeled" gives me the error message, "An improper nine patch image input option was encountered." When I remove that segment of code, it works properly. $\endgroup$ – Joe Oct 30 '14 at 17:40
4
$\begingroup$

You can use Manipulate with two controls, a Slider and an Animator, both attached to a single dynamic variable:

ClearAll[f, h, x];
f[x_] := x^2
a = 2;

Manipulate[
 Plot[{f[x], (f[a + h] - f[a])/h (x - a) + f[a]}, {x, -1, 9}, 
  PlotRange -> {{-1, 4}, {-1, 11}}], 
 Row[{Control[{{h, 1, "h"}, 0.001, 2, Slider[##, Appearance -> "Labeled"] &}],
      Control[{{h, 1, ""}, 0.001, 2, 
        Animator[##, AnimationRunning -> False,
               AppearanceElements -> {"StepLeftButton", "StepRightButton",
                  "PlayPauseButton", "FasterSlowerButtons", "DirectionButton"}] &}]}]]

enter image description here

Note: You can also use just LabeledSlider instead of Slider[##, Appearance -> "Labeled"] &.

$\endgroup$
  • $\begingroup$ I confirm that this works in v7.0.1 $\endgroup$ – Mr.Wizard Oct 30 '14 at 21:19
  • $\begingroup$ @Mr.Wizard, does it work in v10? When I tried on Wolfram Cloud I got the error message "Animator is not currently supported in the Wolfram Cloud". $\endgroup$ – kglr Oct 30 '14 at 21:23
  • $\begingroup$ Yes it does. That is apparently a Cloud limitation. $\endgroup$ – Mr.Wizard Oct 30 '14 at 21:34
  • 1
    $\begingroup$ @Mr.Wizard et al., Animator runs in the front end. The front end clocks the animated variable and triggers the updates when the kernel is ready. That may be the problem. (Mr. Wizard's example doesn't use the kernel at all when it's running.) $\endgroup$ – Michael E2 Oct 30 '14 at 23:39
  • $\begingroup$ Thank you! I don't understand that code, but it works perfectly on my system. $\endgroup$ – Joe Nov 2 '14 at 1:06
9
$\begingroup$

Adding Appearance -> "Labeled" to the control specification seems to work:

Animate["foo", {u, 0, 10, Appearance -> "Labeled"}]

enter image description here


The code above was reported not to work in Mathematica 9. Here is an alternative that works in Mathematica 7.0.1 and presumably 8 and 9 as well:

Animate["foo", {{u, 0, Dynamic[u]}, 0, 10}]

enter image description here

This replaces the label u with the slider value but in many cases I think that could be acceptable.

Alternatively you could simply put the slider value inside the body of the Animate, e.g.:

f[x_] := x^2
a = 2;
Animate[Plot[{f[x], (f[a + h] - f[a])/h (x - a) + f[a]}, {x, -1, 9}, 
   PlotRange -> {{-1, 11}, {-1, 11}}] ~Labeled~ h, {{h, 2}, 0.000001, 2}, 
 AnimationRunning -> False]

enter image description here

$\endgroup$
  • 3
    $\begingroup$ Notably not easily found in the documentation. (One has to guess that Animator options can be used.) +1. $\endgroup$ – Michael E2 Oct 30 '14 at 13:21
  • 1
    $\begingroup$ @MichaelE2, with so many examples of undocumented features brought to light by M.SE users, is there a tag to identify answers such as this (to a specific version of course, eg V10.0.1)? $\endgroup$ – alancalvitti Oct 30 '14 at 13:50
  • $\begingroup$ Thank you for finding that option for me! I searched through the documentation, but couldn't find anything that worked. $\endgroup$ – Joe Oct 30 '14 at 17:35
  • 1
    $\begingroup$ The option Appearance -> "Labeled" is new in V10. See "Show Changes" in the docs for Animator. $\endgroup$ – Michael E2 Oct 30 '14 at 23:11
  • 2
    $\begingroup$ @ivbc Just guesswork, really, built on a familiarity with Mathematica syntax. $\endgroup$ – Mr.Wizard May 11 '17 at 22:43
2
$\begingroup$

Another way, by post-processing the Manipulate code generated by Animate:

labelAnimator = {u_, u1_, u2_, opts___} :>
  {u, u1, u2,
    Labeled[Animator[Dynamic[u], {u1, u2}, opts],
            Pane[Dynamic[u], {50, Automatic}], Right] &};

Animate["foo", {u, 9.12342345, 12, Appearance -> {"Labeled"}, 
   AnimationRunning -> True}] /. labelAnimator

Mathematica graphics

$\endgroup$
  • $\begingroup$ Thank you. You are all very talented at programming in Mathematica. I'm just a user, a math teacher actually. $\endgroup$ – Joe Nov 2 '14 at 1:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.