Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

up vote 6 down vote accepted

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]

enter image description here

Alternatively you could Thread Directive over the colour list:

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

which will give the same result.

share|improve this answer
    
Beat me to it. +1 –  Mr.Wizard Jul 15 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 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 at 12:23

A working way to use Directive:

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

enter image description here

Changing thickness along with color:

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

enter image description here

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},
 ContourShading -> False, 
 ContourStyle -> Directive[AbsoluteThickness[5], Blue]
]

enter image description here

Whereas with { } you would get cyclic styling:

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

enter image description here

share|improve this answer
4  
I think my parents had that wallpaper in the 70s :-) –  Simon Woods Jul 15 at 12:25
    
@SimonWoods LOL (really) –  Mr.Wizard Jul 15 at 12:26
    
Unfortunately, I still don't have Mathematica 10, to get this new amazing wallpapers syntax ! ;) –  jibe Jul 15 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 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 at 12:40

Use Directive

ContourPlot[x+y,{x,-1,1},{y,-1,1},ContourShading->False,Contours->Range[1,10],ContourStyle->Directive[Thick,Red]]
share|improve this answer
1  
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 at 12:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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