# How to control the numbers of points in the range of a plot

Consider the following code:

fun[x_] := x^2;
Plot[fun[x], {x, -4, 4}]


which simply plots a parabola for the range of -4 to 4. I don't know how many points between -4 and 4 Mathematica uses to plot the function? My question is how can I control this number? In fact I have a complicated function which its evaluation takes a long time. On the other hand I need to plot it in range of 0 to 4 to see its shape. When I try Plot command in the range of {0,4} it takes a very very long time to get the curve (it has never finished), so I want to reduce number of points. I took a look on the options of Plot command but I didn't find my desire one. Any idea?

• – kglr
Dec 3 '20 at 14:58
• try also Plot[Evaluate @ yourcomplicatedfunction[x], {x, -4, 4}]
– kglr
Dec 3 '20 at 14:59
• @kglr what does Evaluate command do? Dec 3 '20 at 15:14
• Another thing you might try is to define the function as fun[x_] = x^2; (remove the colon before the equals). This may be why the plotting is so slow. Dec 3 '20 at 15:41
• I meant, just in case, you have a case like this
– kglr
Dec 3 '20 at 15:44

You can use the options PlotPoints and MaxRecursion. For example
fun[x_] := x^2;

• PlotPoints is the number of points? Dec 3 '20 at 15:13
• PlotPoints is the number of initial sampling points. MaxRecursion the number of times the sampling is iterated. As an example, the options PlotPoints -> 5, MaxRecursion -> 0 and PlotPoints -> 2, MaxRecursion -> 2 give the same answer. Dec 3 '20 at 15:16