1""" 2============== 3Manual Contour 4============== 5 6Example of displaying your own contour lines and polygons using ContourSet. 7""" 8import matplotlib.pyplot as plt 9from matplotlib.contour import ContourSet 10import matplotlib.cm as cm 11 12 13############################################################################### 14# Contour lines for each level are a list/tuple of polygons. 15lines0 = [[[0, 0], [0, 4]]] 16lines1 = [[[2, 0], [1, 2], [1, 3]]] 17lines2 = [[[3, 0], [3, 2]], [[3, 3], [3, 4]]] # Note two lines. 18 19############################################################################### 20# Filled contours between two levels are also a list/tuple of polygons. 21# Points can be ordered clockwise or anticlockwise. 22filled01 = [[[0, 0], [0, 4], [1, 3], [1, 2], [2, 0]]] 23filled12 = [[[2, 0], [3, 0], [3, 2], [1, 3], [1, 2]], # Note two polygons. 24 [[1, 4], [3, 4], [3, 3]]] 25 26############################################################################### 27 28fig, ax = plt.subplots() 29 30# Filled contours using filled=True. 31cs = ContourSet(ax, [0, 1, 2], [filled01, filled12], filled=True, cmap=cm.bone) 32cbar = fig.colorbar(cs) 33 34# Contour lines (non-filled). 35lines = ContourSet( 36 ax, [0, 1, 2], [lines0, lines1, lines2], cmap=cm.cool, linewidths=3) 37cbar.add_lines(lines) 38 39ax.set(xlim=(-0.5, 3.5), ylim=(-0.5, 4.5), 40 title='User-specified contours') 41 42############################################################################### 43# Multiple filled contour lines can be specified in a single list of polygon 44# vertices along with a list of vertex kinds (code types) as described in the 45# Path class. This is particularly useful for polygons with holes. 46# Here a code type of 1 is a MOVETO, and 2 is a LINETO. 47 48fig, ax = plt.subplots() 49filled01 = [[[0, 0], [3, 0], [3, 3], [0, 3], [1, 1], [1, 2], [2, 2], [2, 1]]] 50kinds01 = [[1, 2, 2, 2, 1, 2, 2, 2]] 51cs = ContourSet(ax, [0, 1], [filled01], [kinds01], filled=True) 52cbar = fig.colorbar(cs) 53 54ax.set(xlim=(-0.5, 3.5), ylim=(-0.5, 3.5), 55 title='User specified filled contours with holes') 56 57plt.show() 58