Note
Go to the end to download the full example code.
Manual Contour#
Example of displaying your own contour lines and polygons using ContourSet.
import matplotlib.pyplot as plt
from matplotlib.contour import ContourSet
from matplotlib.path import Path
Contour lines for each level are a list/tuple of polygons.
Filled contours between two levels are also a list/tuple of polygons. Points can be ordered clockwise or anticlockwise.
fig, ax = plt.subplots()
# Filled contours using filled=True.
cs = ContourSet(ax, [0, 1, 2], [filled01, filled12], filled=True, cmap="bone")
cbar = fig.colorbar(cs)
# Contour lines (non-filled).
lines = ContourSet(
ax, [0, 1, 2], [lines0, lines1, lines2], cmap="cool", linewidths=3)
cbar.add_lines(lines)
ax.set(xlim=(-0.5, 3.5), ylim=(-0.5, 4.5),
title='User-specified contours')