Reputation: 4771
I'm making a simple contour plot and I want to highlight the zero line by making it thicker and changing the color.
cs = ax1.contour(x,y,obscc)
ax1.clabel(cs,inline=1,fontsize=8,fmt='%3.1f')
How do I achieve this? Thanks :-)
Upvotes: 7
Views: 5008
Reputation: 15345
HTH -- this is basically the contour example taken from the matplotlib docs, just with modified level lines
The object that is returned from the contour
-method holds a reference to the contour lines in its collections
attribute.
The contour lines are just common LineCollections.
In the following code snippet the reference to the contour plot is in CS
(that is cs
in your question):
CS.collections[0].set_linewidth(4) # the dark blue line
CS.collections[2].set_linewidth(5) # the cyan line, zero level
CS.collections[2].set_linestyle('dashed')
CS.collections[3].set_linewidth(7) # the red line
CS.collections[3].set_color('red')
CS.collections[3].set_linestyle('dotted')
type(CS.collections[0])
# matplotlib.collections.LineCollection
Here's how to find out about the levels, if you didn't explicitly specify them:
CS.levels
array([-1. , -0.5, 0. , 0.5, 1. , 1.5])
There is also a lot of functionality to format individual labels:
CS.labelCValueList CS.labelIndiceList CS.labelTextsList
CS.labelCValues CS.labelLevelList CS.labelXYs
CS.labelFmt CS.labelManual CS.labels
CS.labelFontProps CS.labelMappable CS.layers
CS.labelFontSizeList CS.labelTexts
Upvotes: 9