1
$\begingroup$

I want to plot 100 points in a density plot, but don't know how to set the interval of the x and y range.

My code is:

DensityPlot[y + Sin[x^2 + 3 y], {x, -3, 3}, {y, -3, 3}, ColorFunction -> GrayLevel]
$\endgroup$
  • $\begingroup$ does n = 100; ListDensityPlot[ Table[y + Sin[x^2 + 3 y], {y, -3, 3, 6/(n - 1)}, {x, -3, 3, 6/(n - 1)}], ColorFunction -> GrayLevel, DataRange -> {{-3, 3}, {-3, 3}}] give what you need? $\endgroup$ – kglr May 20 at 7:09
3
$\begingroup$

Functions like Plot and DensityPlot normally try to adaptively find a good step size to visualize the function. If you want a plot that simply uses a grid of equally spaced points, you can use the PlotPoints -> n and MaxRecursion -> 0 options:

DensityPlot[y + Sin[x^2 + 3 y], {x, -3, 3}, {y, -3, 3}, 
 ColorFunction -> GrayLevel,
 PlotPoints -> 10,
 MaxRecursion -> 0
]

Setting MaxRecursion -> 0 tells the plotting function to not refine the initial 10 points in the grid.

$\endgroup$

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.