16
$\begingroup$

Bug introduced in 10.0 and fixed in 10.3.0


Check this example:

Manipulate[Grid[{{RandomReal[10]}, {Plot[Sin[x], {x, 0, 2 Pi}]}}], {a, 1, 3}]

enter image description here

As you can see, moving or resizing the Notebook window causes Manipulate to update its argument.

Is this normal behavior of MMA?

Thanks

$\endgroup$
9
  • $\begingroup$ Mine doesn't update when moving the window, but does when resizing (Mac OS 10, Mma 10.0.2). Maybe Manipulate feels like it needs to update the graph, because if you remove this part, it no longer updates when resizing. $\endgroup$
    – bill s
    Commented Feb 7, 2015 at 22:14
  • $\begingroup$ doesn't happen in Version 9.0.1.0 (Windows 8 x64). $\endgroup$
    – kglr
    Commented Feb 7, 2015 at 23:34
  • $\begingroup$ My system is V 10.0.2 (windows 8.1 x64) $\endgroup$ Commented Feb 7, 2015 at 23:37
  • $\begingroup$ Confirmed on V10.0.2 Win7. I'd report it. It is certainly not expected (by me :)). $\endgroup$
    – Kuba
    Commented Feb 8, 2015 at 0:21
  • 1
    $\begingroup$ Probably not related but similar behaviour: WindowSize interfere Dynamic $\endgroup$
    – Kuba
    Commented Feb 8, 2015 at 0:24

4 Answers 4

13
$\begingroup$

I think I've found the guilty : this is PlotTheme

Since the problem seems to only occur when "plot" functions are involved, for example here :

Manipulate[Grid[{{RandomReal[10]}, {Plot[Sin[x], {x, 0, 2 Pi}]}}], {a, 1, 3}]

Manipulate[Grid[{{RandomReal[10]}, {ListPlot[Range[10]]}}], {a, 1, 3}]

Manipulate[
 Grid[{{RandomReal[10]}, {ParametricPlot[{Cos[t], Sin[t]}, {t, 0, Pi}]}}], {a, 1, 3}]

but not in other cases, in particular when other type of graphics are used, like here :

Manipulate[Grid[{{RandomReal[10]}, {RandomReal[10]}}], {a, 1, 3}]

Manipulate[Grid[{{RandomReal[10]}, {Graphics[Disk[]]}}], {a, 1, 3}]

and as there is no problem with version 9, and since PlotTheme was introduced in version 10, I just tested PlotTheme->None, and the problem disappears.

For example :

Manipulate[
 Grid[{{RandomReal[10]}, {Plot[Sin[x], {x, 0, 2 Pi}, PlotTheme -> None]}}], {a, 1, 3}]
$\endgroup$
3
  • $\begingroup$ yes that is the one. +1 $\endgroup$ Commented Feb 20, 2015 at 12:47
  • $\begingroup$ very good finding, much appreciated... $\endgroup$ Commented Feb 20, 2015 at 14:40
  • 2
    $\begingroup$ Another bad boy is PlotLegends : Manipulate[ Grid[{{RandomReal[10]}, {Plot[{Cos[x], Sin[x]}, {x, 0, 2 Pi}, PlotTheme -> None, PlotLegends -> Automatic]}}], {a, 1, 3}] still triggers updating when moving the notebook (M10.2, Windows).@John Fultz: Can we please get a bug fix soon? $\endgroup$ Commented Sep 26, 2015 at 13:11
8
$\begingroup$

This bug has been fixed in Mathematica v10.3.

ScreenDemonstration

$\endgroup$
6
$\begingroup$

I consider this a bug. Although I have no solution, I can provide some further insights. The behavior seems to depend on the usage of any plotting command or commands that display something. The smallest example I could find is

Dynamic[{Plot[Null, {a, 0, 1}], AbsoluteTime[]}]

A simple static Graphics seems not enough, but if you use a Graph instead of the Plot, the behavior appears too. If you look at the cell expression, there seems nothing unusual there

Cell[BoxData[
 DynamicBox[ToBoxes[{
    Plot[Null, {$CellContext`a, 0, 1}], 
    AbsoluteTime[]}, StandardForm],
  ImageSizeCache->{404., {46., 51.}}]], "Output",
 CellChangeTimes->{3.6323472127299213`*^9}]

Therefore, the question is why the front end does trigger a re-evaluation of this DynamicBox.

$\endgroup$
3
$\begingroup$

EDIT: Everyone reading this should be aware that SquareOne's answer contains the real reason and the best way to get rid of these unwanted updates. I'll leave my answer here as I think it shows useful techniques to avoid unwanted updates in similar cases but using PlotTheme->None is certainly the best solution to the OPs problem...

It probably could be argued that the version 10 behavior is OK as the window size might cause changes in any of the manipulates content, e.g. when using something like ImageSize->Full or CurrentValue[EvaluationNotebook[], WindowSize]. The updates when a window moves could then be explained by details of how WindowSizes and WindowMarging are internally handled which would also explain why that seems to be platform dependent. On the other hand it seems to be a confirmed bug and I certainly would consider this an inacceptable misbehavior when using an explicit TrackedSymbols:>{a} to either the Manipulate or an additional Dynamic wrapper for the Plot.

Apart from that I wanted to share a workaround which seems to avoid the problem but is quite some effort to implement in more complicated cases:

DynamicModule[{output, lastValue},
  Manipulate[
    DynamicWrapper[
      output,
      If[lastValue=!= a,
        lastValue = a;
        output = Plot[Sin[x], {x, 0, 2 Pi}, 
           PlotLabel -> {a, RandomReal[]}, 
           ImageSize -> {500, 500./GoldenRatio}
        ]
      ],
      TrackedSymbols :> {a}
    ],
    {a, 1, 3}
  ]
]

the following might make the workaround easier to apply to a larger amount of code:

SetAttributes[saveDynamic,HoldAll];
saveDynamic[expr_,TrackedSymbols:>{symbol_Symbol}]:=DynamicModule[{lastValue,output=""},
    Column[{
    DynamicWrapper[
        Dynamic[output,TrackedSymbols:>{output}],
        If[lastValue=!=symbol,
            lastValue=symbol;
            output=expr
        ],
        TrackedSymbols:>{symbol}
    ]
    }]
];

One could of course adopt this to accept more than one tracked symbol and only use that definition instead of a standard Dynamic for those versions which show the erronous behavior.

$\endgroup$
3
  • $\begingroup$ But for other issues like PlotLegends your solution is much more general and better. I.e., this: DynamicModule[{output, lastValue}, Manipulate[DynamicWrapper[output, If[lastValue =!= a, lastValue = a; output = Column[{RandomReal[], Plot[{Cos[x], Sin[x]}, {x, 0, 2 Pi}, PlotLegends -> "Expressions", PlotLabel -> {a, RandomReal[]}, ImageSize -> {500, 500./GoldenRatio}]}]], TrackedSymbols :> {a}], {a, 1, 3}]] works just fine! $\endgroup$ Commented Sep 26, 2015 at 13:27
  • $\begingroup$ thanks @RolfMertig , I was hoping it would be helpful and left it here because of that. Have you tried if these unexpected updatesx are still an issue with the latest versions? I'm afraid that this behaviour will stay as it is as a fix might make necessary changes at a very deep level for use cases which WRI might classify as "too exotic" for such a change... $\endgroup$ Commented Sep 27, 2015 at 8:44
  • $\begingroup$ @RolfMertig: just have seen your other comment which exactly answers my question... $\endgroup$ Commented Sep 27, 2015 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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