import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
# リスト5.1.1:円弧の描画
# Arc円弧
fig = plt.figure(figsize=(3, 3))
ax = fig.add_subplot(111)
c1 = mpatches.Arc(
xy=(0.4, 0.5),
width=0.4,
height=0.4,
angle=30,
theta1=0,
theta2=230,
linewidth=10,
color="lightblue",
)
c2 = mpatches.Arc(
xy=(0.6, 0.5),
width=0.4,
height=0.4,
angle=30,
theta1=0,
theta2=230,
linewidth=10,
color="pink",
)
ax.add_patch(c1)
ax.add_patch(c2)
plt.show()
# リスト5.1.2:矢印の描画①
# Arrow矢印
fig = plt.figure(figsize=(3, 3))
ax = fig.add_subplot(111)
a1 = mpatches.Arrow(x=0.1, y=0.4, dx=0.6, dy=0.5, width=0.5, color="lightblue")
a2 = mpatches.Arrow(x=0.3, y=0.1, dx=0.6, dy=0.5, width=0.5, color="pink")
ax.add_patch(a1)
ax.add_patch(a2)
plt.show()
# リスト5.1.3:矢印の描画②
# Fancy Arrow矢印
fig = plt.figure(figsize=(3, 3))
ax = fig.add_subplot(111)
a1 = mpatches.FancyArrow(
x=0.2,
y=0.3,
dx=0.4,
dy=0.3,
width=0.1,
head_width=0.3,
head_length=0.2,
shape="right",
color="lightblue",
)
a2 = mpatches.FancyArrow(
x=0.2,
y=0.3,
dx=0.4,
dy=0.3,
width=0.1,
head_width=0.3,
head_length=0.2,
shape="left",
color="pink",
)
ax.add_patch(a1)
ax.add_patch(a2)
plt.show()
# リスト5.1.4:円形の描画
# Circle 円形
fig = plt.figure(figsize=(3, 3))
ax = fig.add_subplot(111)
c1 = mpatches.Circle(xy=(0.5, 0.5), radius=0.4, color="lightblue")
c2 = mpatches.Circle(xy=(0.5, 0.5), radius=0.2, color="white")
ax.add_patch(c1)
ax.add_patch(c2)
plt.show()
# リスト5.1.5:正多角形の描画
# Circle Polygon 正多角形
fig = plt.figure(figsize=(3, 3))
ax = fig.add_subplot(111)
cp1 = mpatches.CirclePolygon(xy=(0.5, 0.5), radius=0.4, resolution=6, color="lightblue")
cp2 = mpatches.CirclePolygon(xy=(0.5, 0.5), radius=0.2, resolution=8, color="white")
ax.add_patch(cp1)
ax.add_patch(cp2)
plt.show()
# リスト5.1.6:楕円形の描画
# Ellipse 楕円形
fig = plt.figure(figsize=(3, 3))
ax = fig.add_subplot(111)
e1 = mpatches.Ellipse(xy=(0.5, 0.5), width=0.8, height=0.5, angle=30, color="lightblue")
e2 = mpatches.Ellipse(xy=(0.5, 0.5), width=0.5, height=0.2, angle=30, color="white")
ax.add_patch(e1)
ax.add_patch(e2)
plt.show()
# リスト5.1.7:扇型の描画
# Wedge 扇型
fig = plt.figure(figsize=(3, 3))
ax = fig.add_subplot(111)
w1 = mpatches.Wedge(center=(0.3, 0.55), r=0.25, theta1=30, theta2=-30, color="pink")
w2 = mpatches.Wedge(
center=(0.7, 0.4), r=0.25, theta1=210, theta2=150, color="lightblue"
)
ax.add_patch(w1)
ax.add_patch(w2)
plt.show()
# リスト5.1.8:四角形の描画
# Rectangle四角形
fig = plt.figure(figsize=(3, 3))
ax = fig.add_subplot(111)
r1 = mpatches.Rectangle(
xy=(0.1, 0.4), width=0.5, height=0.5, angle=0, color="lightblue"
)
r2 = mpatches.Rectangle(xy=(0.4, 0.1), width=0.5, height=0.5, angle=0, color="pink")
ax.add_patch(r1)
ax.add_patch(r2)
plt.show()
# リスト5.1.9:多角形の描画
# Polygon 多角形
fig = plt.figure(figsize=(3, 3))
ax = fig.add_subplot(111)
p1 = mpatches.Polygon(xy=[(0, 0.2), (0.3, 0.8), (0.6, 0.2)], facecolor="lightblue")
p2 = mpatches.Polygon(xy=[(0.4, 0.8), (0.7, 0.2), (1.0, 0.8)], facecolor="pink")
ax.add_patch(p1)
ax.add_patch(p2)
plt.show()