6
$\begingroup$

While manipulating the slider in Manipulate[], I experience choppy curves. These do however render correctly after letting go of the slider. The same phenomenon occurs when pressing the + or - button or play-button.

An example of this is shown below.

The question is of course how to avoid this. Any suggestions?

Manipulate[
 Plot[Sin[x] + Sin[a x], {x, 0, 10}, 
  PlotStyle -> Thickness[0.002]], {{a, 10}, 1, 100, 1}]

Plot while holding the slider: enter image description here

After some seconds a smooth plot is presented: enter image description here

EDIT: Applying PerformanceGoal -> "Quality" suggested by kguler solves this problem, however some gaps appear at certain values, see below: enter image description here

$\endgroup$
6
  • $\begingroup$ Closely related: 45858 and probably a duplicate $\endgroup$
    – Kuba
    Sep 16, 2014 at 19:25
  • $\begingroup$ @Kuba, yes you are correct. However in spite of searching a good while before posting, I didn't find them. How did you find them so fast? $\endgroup$
    – MathLind
    Sep 16, 2014 at 20:22
  • $\begingroup$ I knew what to look for so don't blame yourself :) $\endgroup$
    – Kuba
    Sep 16, 2014 at 20:46
  • 1
    $\begingroup$ Regarding the second problem you can use ControlActive to specify sufficiently high PlotPoints. Please see these for an understanding of the problem: (4572183), (29346) Also my own answer to: (8482) $\endgroup$
    – Mr.Wizard
    Sep 17, 2014 at 14:25
  • $\begingroup$ @Mr.Wizard, Thank you for the highly instructive links. Again, I'm amazed how you find these links. $\endgroup$
    – MathLind
    Sep 17, 2014 at 14:37

2 Answers 2

5
$\begingroup$

Use the option PerformanceGoal->"Quality":

Manipulate[
 Plot[Sin[x] + Sin[a x], {x, 0, 10}, PlotStyle -> Thickness[0.002], 
  PerformanceGoal -> "Quality"], {{a, 10}, 1, 100, 1}]

From the docs:

PerformanceGoal > Details

The typical default setting for PerformanceGoal is $PerformanceGoal.

\$PerformanceGoal > Details

The typical default value of $PerformanceGoal is ControlActive["Speed","Quality"].

$\endgroup$
3
  • $\begingroup$ This solves the issue. But if I set "a" to 89 in your example, I get a big gap around 1<x<1.25 at least on my screen. Do you experience this as well? $\endgroup$
    – MathLind
    Sep 16, 2014 at 19:28
  • 1
    $\begingroup$ @MathLind, yes i see the same gap (version 9.0.1.0 Windows 8 64bit). See also a=53. Setting PlotPoints and MaxRecursion very high (e.g., PlotPoints -> 200, MaxRecursion -> 15)seems to get rid of such gaps -- at the cost of speed, of course. $\endgroup$
    – kglr
    Sep 16, 2014 at 19:36
  • $\begingroup$ PlotPoints -> 200, MaxRecursion -> 5seems to suffice on my system. The lagging is bearable. $\endgroup$
    – MathLind
    Sep 16, 2014 at 19:58
3
$\begingroup$

You can use PlotPoints adaptively so to calculate one point per period (aprox)

Manipulate[
 Plot[Sin[x] + Sin[a x], {x, 0, 10}, PlotStyle -> Thickness[0.002], 
  PlotPoints -> IntegerPart[10  a/2 Pi] ], {{a, 10}, 1, 100, 1}]

Mathematica graphics

$\endgroup$

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