Select a single contour line.

I am making a simple contour plot, and I want to highlight the zero line, 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: -)

+4
source share
1 answer

HTH is basically an example contour taken from matplotlib docs , only with level lines changed

The object returned by the contour method contains a reference to the contour lines in its collections attribute. Contour lines are just plain LineCollections.

In the following code snippet, the link to the contour plot is in CS (i.e. 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 levels, unless you explicitly specify them:

 CS.levels array([-1. , -0.5, 0. , 0.5, 1. , 1.5]) 

There are also many functions for formatting 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 
+5
source

All Articles