How to do it…

Enter the following code in a Jupyter execution cell and run it:

from matplotlib.patches import Rectangle, Circle, Polygon
from matplotlib.text import Text
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
options = dict(xlim=(0,20), ylim=(0,20), aspect='equal',
xticks=[], yticks=[])
ax.update(options)
rect = Rectangle((3,3), width=7, height=7,
color='orange', ec='black')
circle = Circle((13,6.5), radius=5,
color='green', ec='darkgreen',
alpha=0.7)
vertices = np.array([[1, 11],[10,18],
[15,5],[2,19]])
poly = Polygon(vertices, color='blue', lw=4,
closed=False, fill=None)
for patch in [rect, circle, poly]:
ax.add_patch(patch)
text = Text(12, 14, "Hello, World!", color='red',
family='sans-serif', fontsize=26)
ax.add_artist(text)
None

Running this code will produce output similar to the following screenshot:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset