# How to simultaneously change the color and thickness in ContourStyle?

When plotting contours with ContourPlot, one can use the option ContourStyle to change the contours of the plot.

With the instruction,

ContourPlot[f[x,y],{x,-1,1},{y,-1,1},ContourShading -> False, Contours -> Range[1,10], ContourStyle -> ColorData[10] /@ Range[10]]


I am able to change the colors of the contours, but they are thin.

On the other hand, if I use the instruction

ContourPlot[f[x,y],{x,-1,1},{y,-1,1},ContourShading -> False, Contours -> Range[1,10], ContourStyle -> Thick]


I am able to draw thicker contour lines, however, they are black.

I would like to draw the same contours simultaneously thicker and colored.

How could I proceed ?

Mathematica seems to indicate to use Directive[...], but I have not been able to use it...

You could use BaseStyle to set the Thick lines:

ContourPlot[x y, {x, -1, 1}, {y, -1, 1}, ContourShading -> False,
ContourStyle -> ColorData[10] /@ Range[10],
BaseStyle -> Thick]


Alternatively you could Thread Directive over the colour list:

ContourStyle -> Thread @ Directive[Thick, ColorData[10] /@ Range[10]]


which will give the same result.

• Beat me to it. +1 Commented Jul 15, 2014 at 12:19
• This answers exactly my question. It is based on the fact that the same thickness of the lines is shared between all the contours. For my own curiosity, would you know how to adapt the thickness from one line to another, simultaneously with the colors ? (If it is too involved, don't bother of course !)
– jibe
Commented Jul 15, 2014 at 12:21
• @jibe See my answer for that variation. If you don't need that level of specificity I prefer BaseStyle. Commented Jul 15, 2014 at 12:23

A working way to use Directive:

ContourPlot[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi},
ContourStyle -> Array[Directive[Thick, ColorData[10]@#] &, 10]
]


Changing thickness along with color:

ContourPlot[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi},
ContourStyle -> Array[{AbsoluteThickness[#], ColorData[10]@#} &, 10]
]


The same result may be had using { } or Directive[ ] (for both variations).
Directive should be needed only when providing multiple style rules that are to apply to all lines, like this:

ContourPlot[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi},
ContourStyle -> Directive[AbsoluteThickness[5], Blue]
]


Whereas with { } you would get cyclic styling:

ContourPlot[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi},
ContourStyle -> {AbsoluteThickness[5], Blue}
]


• I think my parents had that wallpaper in the 70s :-) Commented Jul 15, 2014 at 12:25
• @SimonWoods LOL (really) Commented Jul 15, 2014 at 12:26
• Unfortunately, I still don't have Mathematica 10, to get this new amazing wallpapers syntax ! ;)
– jibe
Commented Jul 15, 2014 at 12:30
• @jibe I'm not sure if that's a joke or if the second code doesn't work for you. If the latter, what version are you using? Please try this code from before I replaced Directive. Commented Jul 15, 2014 at 12:33
• @Mr.Wizard Your two codes examples work perfectly well for me with Directive[] (which is what I had only tried.). Quite surprinsigly, I have Mathematica 9. and the version with {} instead of Directive also works (I just tried it.)
– jibe
Commented Jul 15, 2014 at 12:40

One can also modify the resulting graphic directly:

original = ContourPlot[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi},
PlotLegends -> Automatic, Contours -> 10, ContourShading -> False,
ContourStyle -> ColorData["AvocadoColors"] /@ Rescale@Array[# &, 10],
PlotPoints -> 100];

original /. RGBColor[a__] :> Sequence[Thick, RGBColor@a]


The advantage of this method is, it also adjusts the thickness of lines in legend, while the solutions shown by Simon and Mr.Wizard doesn't, at least in v12.2.

• I personally prefer using Directive[] instead of Sequence[] in a situation like this: original /. RGBColor[a__] :> Directive[Thick, RGBColor[a]] Commented Dec 25, 2020 at 7:16

Use Directive

ContourPlot[x+y,{x,-1,1},{y,-1,1},ContourShading->False,Contours->Range[1,10],ContourStyle->Directive[Thick,Red]]

• Thank you, now all the contours are simultaneously thick and red. However, I would also like the colors to change from one contour to another, as in my first example. Would you know how to adapt your answer ?
– jibe
Commented Jul 15, 2014 at 12:15