4
$\begingroup$

Is there a way to tell Mathematica to use plain lines for contour lines associated with positive level values and dashed otherwise ?

Can't seem to find anything in the help documentation.

Thanks for the help.

$\endgroup$
2

4 Answers 4

8
$\begingroup$

Maybe this? :

ContourPlot[Evaluate@((x*y == #) & /@ Range[-8, 8, 1]), {x, -3, 3}, {y, -3, 3}, ContourStyle -> (If[# >= 0, {Directive[Red]}, {Directive[Blue, Dashed]}] & /@ Range[-8, 8, 1])] 

enter image description here

$\endgroup$
5
$\begingroup$
f[x_, y_] = x*y; Show[ ContourPlot[f[x, y], {x, -3, 3}, {y, -3, 3}, Contours -> Range[1, 8], ContourShading -> None, ContourStyle -> Red], ContourPlot[f[x, y], {x, -3, 3}, {y, -3, 3}, Contours -> Range[-8, -1], ContourShading -> None, ContourStyle -> Directive[Blue, Dashed]], ContourPlot[f[x, y], {x, -3, 3}, {y, -3, 3}, Contours -> {0}, ContourShading -> None, ContourStyle -> Directive[Lighter[Gray], AbsoluteThickness[1]]]] 

enter image description here

$\endgroup$
1
  • $\begingroup$ I must be missing something. Why would this answer be downvoted? Bob's answer also anticipates a zero contour. $\endgroup$ Commented Jan 29, 2018 at 23:12
1
$\begingroup$

This hack-ish method relies on ContourPlot[] generating contours with the $z$-value being stored in a Tooltip[]:

ContourPlot[x y, {x, -3, 3}, {y, -3, 3}, Contours -> 12, ContourShading -> None, ContourStyle -> {}] /. Tooltip[prims_, val_] :> Tooltip[Prepend[prims, Switch[Sign[val], -1, Directive[Blue, Dashed], 0, Opacity[1/2, Gray], 1, Red]], val] 

differently-colored contours

$\endgroup$
0
$\begingroup$

Yes, you can create two separate plots (one for positive, one for negative), and combine them:

Show[{ContourPlot[{Abs[Sin[x] Sin[y]] == 0.5, Abs[Cos[x] Cos[y]] == 0.5}, {x, -3, 3}, {y, -3, 0}, ContourStyle -> Dashed], ContourPlot[{Abs[Sin[x] Sin[y]] == 0.5, Abs[Cos[x] Cos[y]] == 0.5}, {x, -3, 3}, {y, 0, 3}]}, PlotRange -> All] 

image

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.