All the methods below add three styled curves, "while all other curves stay in the default style."
ContourPlot
1. You can use the options MeshFunctions
and Mesh
to add additional contours:
ContourPlot[Sin[x - y] + Cos[x + y], {x, -10, 10}, {y, -10, 10},
PlotPoints -> {30, 30}, PlotRange -> {{-10, 10}, {-10, 10}},
ColorFunction -> "Rainbow", ImageSize -> 500,
MeshFunctions -> {Sin[# - #2] + Cos[# + #2] &},
Mesh -> {Thread[{{0., -1., 1.},
Thread[Directive[{Green, Red, Blue}, Thick, Opacity[1]]]}]}]
2. Generate the list of contours using FindDivisions
and style each contour as you like:
automaticcontours = FindDivisions[{-2, 2}, 10];
styledcontours = {{-1, Directive[Thick, Red]},
{0, Directive[Thick, Green]}, {1, Directive[Thick, Blue]}};
contours = DeleteDuplicatesBy[First]@
Join[styledcontours, Thread[{automaticcontours, Automatic}]];
ContourPlot[Sin[x - y] + Cos[x + y], {x, -10, 10}, {y, -10, 10},
PlotPoints -> {30, 30}, PlotRange -> {{-10, 10}, {-10, 10}},
ColorFunction -> "Rainbow", ImageSize -> 500,
Contours -> contours]
3. Post-process ContourPlot
output to restyle selected contours:
cp = ContourPlot[Sin[x - y] + Cos[x + y], {x, -10, 10}, {y, -10, 10},
PlotPoints -> {30, 30}, PlotRange -> {{-10, 10}, {-10, 10}},
ColorFunction -> "Rainbow", ImageSize -> 500];
Replace[cp, {Tooltip[{d___, l__Line}, t : (0. | 1. | -1.)] :> {Thick, Opacity[1],
t /. {0. -> Green, -1. -> Red, 1. -> Blue, _ -> {d}}, Tooltip[{l}, t]}}, All]
4. Yet another method is to extract the contours from cp
and redo ContourPlot
using styled contours:
automaticcontours = Cases[cp, Tooltip[_, t_] :> t, All]
{1.5, 1., 0.5, 0., -0.5, -1., -1.5};
styledcontours = Thread[{{0., -1., 1.},
Thread[Directive[{Green, Red, Blue}, Thick, Opacity[1]]]}];
contours = Join[styledcontours , Complement[automaticcontours, {0., -1., 1.}]];
ContourPlot[Sin[x - y] + Cos[x + y], {x, -10, 10}, {y, -10, 10},
PlotPoints -> {30, 30}, PlotRange -> {{-10, 10}, {-10, 10}},
ColorFunction -> "Rainbow", ImageSize -> 500,
Contours -> contours]
Plot3D
1. Use FindDivisions
to generate a mesh list (that matches the automatically generated one) and add your list of styled mesh lines and use the combined list as the setting for Mesh
:
automaticmeshlines = Most @ Rest @ FindDivisions[{-2, 2}, 18];
styledmeshlines = {{-1, Directive[Thick, Red]}, {0,
Directive[Thick, Green]}, {1, Directive[Thick, Blue]}};
mesh = DeleteDuplicatesBy[First]@
Join[styledmeshlines, Thread[{automaticmeshlines , Automatic}]];
Plot3D[Sin[x - y] + Cos[x + y], {x, -10, 10}, {y, -10, 10},
PlotPoints -> {30, 30}, PlotRange -> {{-10, 10}, {-10, 10}, {-3, 3}},
ColorFunction -> "Rainbow", ImageSize -> 500,
Method -> {"RotationControl" -> "Globe"}, SphericalRegion -> True,
MeshFunctions -> {#3 &},
Mesh -> {mesh}]
2. Add constant functions in the first argument of Plot3D
corresponding to the desired levels, set their PlotStyle
to Opacity[0]
and use the option BoundaryStyle
to set the directives for the intersection of the main surface with the added planes:
Plot3D[{ 0., -1., 1., Sin[x - y] + Cos[x + y]}, {x, -10, 10}, {y, -10,
10}, PlotPoints -> {30, 30},
PlotRange -> {{-10, 10}, {-10, 10}, {-3, 3}},
MeshFunctions -> (#3 &),
PlotStyle -> {Opacity[0], Opacity[0], Opacity[0], Automatic},
ColorFunction -> "Rainbow", ImageSize -> 500,
BoundaryStyle -> {1 -> None, 2 -> None, 3 -> None,
{4, 1} -> Directive[Green, AbsoluteThickness[4], Opacity[1]],
{4, 2} -> Directive[Red, AbsoluteThickness[4], Opacity[1]],
{4, 3} -> Directive[Blue, AbsoluteThickness[4], Opacity[1]]},
Method -> {"RotationControl" -> "Globe"}, SphericalRegion -> True]
3. Post-process to restyle selected mesh lines:
p3d = Plot3D[Sin[x - y] + Cos[x + y], {x, -10, 10}, {y, -10, 10},
PlotPoints -> {30, 30},
PlotRange -> {{-10, 10}, {-10, 10}, {-3, 3}},
MeshFunctions -> (#3 &), ColorFunction -> "Rainbow",
ImageSize -> 500, Method -> {"RotationControl" -> "Globe"},
SphericalRegion -> True];
Normal[p3d] /. Line[x_, ___] :>
{Round[x[[1, -1]], 0.1] /. Append[Thread[{0., -1., 1.} ->
Thread[Directive[{Green, Red, Blue}, Thick, Opacity[1]]]], _ -> {}], Line[x]}