# リスト5.4.1:線の色と太さの設定
import matplotlib.pyplot as plt
import numpy as np
plt.style.use("ggplot")
x = np.array([0, 1])
y = [0, 1]
fig = plt.figure(figsize=(9, 3))
ax = fig.add_subplot(111, xlim=(-0.2, 4))
# 線の太さと透明度を設定して描画
ax.plot(x, y, linewidth=1, color="b", label="linewidth=1(alpha=1.0)")
ax.plot(x + 0.1, y, linewidth=1, color="b", alpha=0.5, label="linewidth=1(alpha=0.5)")
ax.plot(x + 0.3, y, linewidth=2, color="b", label="linewidth=2(alpha=1.0)")
ax.plot(x + 0.4, y, linewidth=2, color="b", alpha=0.5, label="linewidth=2(alpha=0.5)")
ax.plot(x + 0.7, y, linewidth=5, color="b", label="linewidth=5(alpha=1.0)")
ax.plot(x + 0.8, y, linewidth=5, color="b", alpha=0.5, label="linewidth=5(alpha=0.5)")
ax.plot(x + 1.1, y, linewidth=10, color="b", label="linewidth=10(alpha=1.0)")
ax.plot(x + 1.3, y, linewidth=10, color="b", alpha=0.5, label="linewidth=10(alpha=0.5)")
ax.legend()
plt.show()
<matplotlib.figure.Figure at 0x24de00e2a20>
# リスト5.4.2:線の末端形状の設定
x = [0.1, 1]
y = np.array([0, 0])
fig = plt.figure(figsize=(6, 3))
ax = fig.add_subplot(111, xlim=(0, 1.7), ylim=(-0.2, 1.2))
# 線の末端形状を設定して描画
ax.plot(x, y + 1, linewidth=12, solid_capstyle="butt", label="butt")
ax.plot(x, y + 0.5, linewidth=12, solid_capstyle="round", label=" round")
ax.plot(x, y, linewidth=12, solid_capstyle="projecting", label=" projecting")
ax.legend(loc=1)
plt.show()
# リスト5.4.3:線の結合部の形状の設定
x = np.array([0, 1, 2, 3])
y = [0, 1.0, 0.2, 1.2]
fig = plt.figure(figsize=(6, 3))
ax = fig.add_subplot(111, xlim=(0, 4.5))
# 線の結合部の形状を設定して描画
ax.plot(x, y, linewidth=10, solid_joinstyle="miter", label="miter")
ax.plot(x + 0.5, y, linewidth=10, solid_joinstyle="round", label="round")
ax.plot(x + 1.0, y, linewidth=10, solid_joinstyle="bevel", label="bevel")
ax.legend()
plt.show()
# リスト5.4.4:線種を設定
x = np.array([0, 1])
y = np.array([1.9, 1.9])
fig = plt.figure(figsize=(6, 4))
ax = fig.add_subplot(111, xlim=(-0.1, 1.7), ylim=(0, 2))
# 線種を設定して描画
ax.plot(x, y, linewidth=5, color="b", linestyle="solid", label="solid")
ax.plot(x, y - 0.1, linewidth=5, color="b", alpha=0.5, linestyle="-", label="-")
ax.plot(x, y - 0.4, linewidth=5, color="b", linestyle="dashed", label="dashed")
ax.plot(x, y - 0.6, linewidth=5, color="b", alpha=0.5, linestyle="--", label="--")
ax.plot(x, y - 0.9, linewidth=5, color="b", linestyle="dashdot", label="dashdot")
ax.plot(x, y - 1.0, linewidth=5, color="b", alpha=0.5, linestyle="-.", label="-.")
ax.plot(x, y - 1.3, linewidth=5, color="b", linestyle="dotted", label="dotted")
ax.plot(x, y - 1.4, linewidth=5, color="b", alpha=0.5, linestyle=":", label=":")
ax.plot(x, y - 1.7, linewidth=5, color="g", linestyle=(0, (5, 2)), label="(0, (5, 2))")
ax.plot(x, y - 1.8, linewidth=5, color="g", linestyle=(4, (5, 2)), label="(4, (5, 2))")
ax.legend()
plt.show()
# リスト5.4.5:破線・点線の末端形状の設定
x = [0.1, 1]
y = np.array([0, 0])
fig = plt.figure(figsize=(6, 3))
ax = fig.add_subplot(111, xlim=(0, 1.7), ylim=(-0.2, 1.2))
# 破線 ・ 点線の末端形状を設定して描画
ax.plot(x, y + 1, linewidth=12, linestyle="-.", dash_capstyle="butt", label="butt")
ax.plot(x, y + 0.5, linewidth=12, linestyle="-.", dash_capstyle="round", label=" round")
ax.plot(x, y, linewidth=12, linestyle="-.", dash_capstyle="projecting", label=" projecting")
ax.legend()
plt.show()
# リスト5.4.6:破線の結合形状の設定
x = np.array([0, 1, 2, 3])
y = [0, 1.0, 0.2, 1.2]
fig = plt.figure(figsize=(6, 3))
ax = fig.add_subplot(111, xlim=(0, 4.5))
# 破線の結合形状を変えて描画
ax.plot(x, y, linewidth=10, linestyle=(0, (3, 0.5)),
dash_joinstyle="miter", label="miter")
ax.plot(x + 0.5, y, linewidth=10, linestyle=(0, (3, 0.5)),
dash_joinstyle="round", label="round")
ax.plot(x + 1.0, y, linewidth=10, linestyle=(0, (3, 0.5)),
dash_joinstyle="bevel", label="bevel")
ax.legend()
plt.show()