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

pylab_examples example code:

Next topic

pylab_examples example code:

This Page

pylab_examples example code: hatch_demo.pyΒΆ

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

Hatching (pattern filled polygons) is supported currently in the PS,
PDF, SVG and Agg backends only.
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse, Polygon

fig = plt.figure()
ax1 = fig.add_subplot(131),5), range(1,5), color='red', edgecolor='black', hatch="/"),5), [6] * 4, bottom=range(1,5), color='blue', edgecolor='black', hatch='//')

ax2 = fig.add_subplot(132)
bars =,5), range(1,5), color='yellow', ecolor='black') + \, 5), [6] * 4, bottom=range(1,5), color='green', ecolor='black')

patterns = ('-', '+', 'x', '\\', '*', 'o', 'O', '.')
for bar, pattern in zip(bars, patterns):

ax3 = fig.add_subplot(133)
ax3.fill([1,3,3,1],[1,1,2,2], fill=False, hatch='\\')
ax3.add_patch(Ellipse((4,1.5), 4, 0.5, fill=False, hatch='*'))
ax3.add_patch(Polygon([[0,0],[4,1.1],[6,2.5],[2,1.4]], closed=True,
                      fill=False, hatch='/'))

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