# 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 – Mr.Wizard Jul 15 '14 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 Jul 15 '14 at 12:21
@jibe See my answer for that variation. If you don't need that level of specificity I prefer BaseStyle. – Mr.Wizard Jul 15 '14 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 :-) – Simon Woods Jul 15 '14 at 12:25
@SimonWoods LOL (really) – Mr.Wizard Jul 15 '14 at 12:26
Unfortunately, I still don't have Mathematica 10, to get this new amazing wallpapers syntax ! ;) – jibe Jul 15 '14 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. – Mr.Wizard Jul 15 '14 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 Jul 15 '14 at 12:40

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 Jul 15 '14 at 12:15