3
$\begingroup$

How do I change the color of a specific curve in my ContourPlot? I want to change the color of the last curve (+1.5 additive factor) from purple to gray. Here's my code:

ContourPlot[{Sin[2 y] == -2/3 Cos[3 x] - 1.5, 
  Sin[2 y] == -2/3 Cos[3 x] - 1, Sin[2 y] == -2/3 Cos[3 x], 
  Sin[2 y] == -2/3 Cos[3 x] + 1, 
  Sin[2 y] == -2/3 Cos[3 x] + 1.5}, {x, -2 Pi, 2 Pi}, {y, -2 Pi, 
  2 Pi}]
$\endgroup$

closed as off-topic by MarcoB, m_goldberg, Bob Hanlon, Carl Lange, Öskå Mar 7 at 21:58

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – MarcoB, m_goldberg, Bob Hanlon, Carl Lange, Öskå
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ Combine separate plots with Show is one simple way that comes to mind. $\endgroup$ – Michael E2 Mar 5 at 14:27
  • $\begingroup$ That was really helpful. Thank you! @MichaelE2 $\endgroup$ – Levy Mar 5 at 14:35
  • 3
    $\begingroup$ Or ContourPlot[ Evaluate[(Sin[2 y] == -2/3 Cos[3 x] - #) & /@ {-3/2, -1, 0, 1, 3/2}], {x, -2 Pi, 2 Pi}, {y, -2 Pi, 2 Pi}, ContourStyle -> {Automatic, Automatic, Automatic, Automatic, LightGray}, PlotLegends -> "Expressions"] where I have used LightGray rather than Gray to make the difference easier to see. $\endgroup$ – Bob Hanlon Mar 5 at 15:00
5
$\begingroup$

Two more methods in addition to the ones mentioned in comments by Michael E2 and Bob Hanlon:

  1. Post-process Purple (actually, ColorData[97][5]) to Gray:

contours = {-3/2, -1, 0, 1, 3/2};
ContourPlot[Evaluate[Sin[2 y] + 2/3 Cos[3 x] == # & /@ contours],
  {x, -2 Pi, 2 Pi}, {y, -2 Pi, 2 Pi}] /. 
    Directive[___, ColorData[97][5], ___] :> Directive[AbsoluteThickness[3], Gray]

enter image description here

  1. Use a single function and style the contours using the {{contour1, style1}..} form for setting the option Contours:

styles = Append[ColorData[97] /@ Range[4], Directive[Thick, Gray]];
ContourPlot[Sin[2 y] - 2/3 Cos[3 x], {x, -2 Pi, 2 Pi}, {y, -2 Pi, 2 Pi}, 
 Contours -> Thread[{contours, styles}], ContourShading -> None, 
 PlotLegends -> LineLegend[styles, Sin[2 y] - 2/3 Cos[3 x] == # & /@ contours]]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you very much! It worked great. $\endgroup$ – Levy Mar 6 at 12:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.