How to | Make a Smoother or Rougher Plot
The Wolfram Language gives you the ability to fine-tune the level of detail for your plots. To get a rough sketch of a plot, you can tell the Wolfram Language to plot fewer points. The more points you have in a plot, the more detailed the results will be.
First, plot a simple function:
Plot[Abs[Sin[x]], {x, 0, 2 π}]Set the option Mesh->All to see the default sample points that the Wolfram Language uses:
Plot[Abs[Sin[x]], {x, 0, 2 π}, Mesh -> All]You can adjust the number of sample points plotted with PlotPoints. MaxRecursion controls how many recursive subdivisions can be made:
Manipulate[With[{p = p, m = m}, Show[Plot[Abs[Sin[x]], {x, 0, 2 π}, Mesh -> All, PlotPoints -> p, MaxRecursion -> m, PlotRange -> {-0.5, 1}, ImageSize -> Medium], Graphics[Style[Text["PlotPoints: " <> ToString[p], {2, -0.25}], 14]], Graphics[Style[Text["MaxRecursion: " <> ToString[m], {2, -0.4}], 14]]]], {{p, 3, "PlotPoints"}, 3, 20, 1}, {{m, 0, "MaxRecursion"}, 0, 10, 1}]Setting values for PlotPoints and MaxRecursion high makes a very detailed picture at the cost of speed. AbsoluteTiming prints how long (in seconds) it takes to evaluate:
AbsoluteTiming[Plot3D[Abs[Sin[x + y]], {x, -2 π, 2 π}, {y, -2 π, 2 π}, PlotPoints -> 10, MaxRecursion -> 8]]Smaller values for PlotPoints and MaxRecursion give a rougher but much faster result:
AbsoluteTiming[Plot3D[Abs[Sin[x + y]], {x, -2 π, 2 π}, {y, -2 π, 2 π}, PlotPoints -> 4, MaxRecursion -> 4]]You can get a misleading result if these parameter values are chosen poorly. This is the accurate plot produced by the Wolfram Language's default settings:
Plot[Sin[x], {x, -100, 100}]//TimingSetting PlotPoints too low yields a misleading result:
Plot[Sin[x], {x, -100, 100}, PlotPoints -> 2]//TimingYou can compensate for a low PlotPoints value by increasing MaxRecursion, but this will often take much longer, and may still be inaccurate:
Plot[Sin[x], {x, -100, 100}, PlotPoints -> 2, MaxRecursion -> 15]//Timing