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.
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.
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])] 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]]]] 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] 
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]