1
$\begingroup$

I'm struggling to increase the number of contour lines shown on this graph, and preferably there are more contour lines between x+y==0 and x+y==2.

ContourPlot[x + y, {x, -1, 3}, {y, 0, 2}, ContourStyle -> Red, ContourShading -> False]

Neither MaxIteration nor Plotpoints seems to change the graph; there are always 5 lines shown.

Edit: with Contours I can make more equally spaced contours, but how can I make it such that it's twice as dense inside the region of x+y==0 and x+y==2 ?

$\endgroup$
2
  • 1
    $\begingroup$ You could try Contours -> 10 or Contours -> 20 etc... and see if this does what you want. $\endgroup$
    – Nasser
    Commented Jan 19, 2021 at 7:24
  • 1
    $\begingroup$ If you look at the docs for Contours, you should notice that you can specify particular $z$-values... $\endgroup$ Commented Jan 19, 2021 at 7:45

1 Answer 1

1
$\begingroup$

One way is use Mesh.

ContourPlot[x + y, {x, -1, 3}, {y, 0, 2}, ContourStyle -> Red, 
 ContourShading -> False, Contours -> 5, 
 MeshFunctions -> Function[{x, y}, x + y], Mesh -> {Range[1, 2, .1]}, 
 MeshStyle -> Red]

Or

ContourPlot[x + y, {x, -1, 3}, {y, 0, 2}, ContourStyle -> Red, 
 ContourShading -> False, 
 Contours -> Join[{-1, 0}, Range[1, 2, .1], {3, 4}]]

enter image description here

$\endgroup$
2
  • $\begingroup$ useful options for this special case PlotPoints -> 2 and MaxRecursion -> 0 $\endgroup$
    – I.M.
    Commented Jan 19, 2021 at 8:41
  • $\begingroup$ The mesh functions are powerful! The document for it in ContourPlot is quite limited, so thanks for showing how these can be done! $\endgroup$
    – K.Mole
    Commented Jan 20, 2021 at 2:34

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.