You are reading an old version of the documentation (v1.4.3). For the latest version see

We're updating the default styles for Matplotlib 2.0

Learn what to expect in the new updates


Previous topic

api example code:

Next topic

api example code:

This Page

api example code: compound_path.pyΒΆ

(Source code, png, hires.png, pdf)

Make a compund path -- in this case two simple polygons, a rectangle
and a triangle.  Use CLOSEOPOLY and MOVETO for the different parts of
the compound path
import numpy as np
from matplotlib.path import Path
from matplotlib.patches import PathPatch
import matplotlib.pyplot as plt

vertices = []
codes = []

codes = [Path.MOVETO] + [Path.LINETO]*3 + [Path.CLOSEPOLY]
vertices = [(1,1), (1,2), (2, 2), (2, 1), (0,0)]

codes += [Path.MOVETO] + [Path.LINETO]*2 + [Path.CLOSEPOLY]
vertices += [(4,4), (5,5), (5, 4), (0,0)]

vertices = np.array(vertices, float)
path = Path(vertices, codes)

pathpatch = PathPatch(path, facecolor='None', edgecolor='green')

fig, ax = plt.subplots()
ax.set_title('A compound path')


Keywords: python, matplotlib, pylab, example, codex (see Search examples)