Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

highlight single contour line

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 :-)

like image 937
Shejo284 Avatar asked Jan 10 '13 17:01

Shejo284


People also ask

How to plot single contour?

To display a single contour line, define v as a two-element vector with both elements equal to the desired contour level. For example, create a 3-D contour of the peaks function. To display only one contour level at Z = 1 , define v as [1 1] .

Are contour lines parallel?

Other characteristics of contour lines are: - Along plane surfaces, contour lines are straight and parallel. - Contour lines are perpendicular to lines of steepest slopes. - For summits or depressions, contour lines most close upon themselves.

How do you define contour levels in Matlab?

To draw the contour lines at specific heights, specify levels as a vector of monotonically increasing values. To draw the contours at one height ( k ), specify levels as a two-element row vector [k k] . contour(___, LineSpec ) specifies the style and color of the contour lines.


1 Answers

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
like image 129
tzelleke Avatar answered Sep 18 '22 20:09

tzelleke