Example Some Other Patches

The code in Listing 6-15 generates a list of patch objects and attaches them to a figure. The figure is originally empty.

Listing 6-15. Some Patches from pylab import *

# Import Ellipse and Wedge to current namespace from matplotlib.patches import Ellipse, Wedge

Arrow(0, 4, 0, -4, facecolor='g'), Circle([-2, 2], 1.5, linewidth=4, fc='orange'), Ellipse([2, 3], 4, 1, 45.0, edgecolor='r'),

Polygon([[4, 2], [3, 3], [1, -1], [3, -1]], ls='dashed', fill=False), Wedge([-1, 0], 3, 200, 300, fc='m', ec='m'),

Rectangle([l, -2], 3, -2, fill=False, lw=5, ec='r') ]

# draw a figure figure()

for p in my_patches: cur_ax.add_patch(p)

title('Patches')

Figure 6-18 shows the results of the code in Listing 6-15.

Patches

Patches

Figure 6-18. Some patches

The patch objects Ellipse and Wedge are not automatically imported to the current namespace when you issue from pylab import * (unlike Arrow, Circle, Polygon, and Rectangle), so I've manually imported them to the namespace with the statement from matplotlib.patches import Ellipse, Wedge.

I've also passed arguments to the patches to show how to use them: facecolor (or fc), edgecolor (or ec), linestyle (or Is), linewidth (or lw), and fill.

Was this article helpful?

0 0

Post a comment