FancyBboxPatchクラス
matplotlib.patches モジュールの FancyBboxPatchクラスには、長方形をベースに角を丸めたり、辺をギザギザにしたりといった特殊な図形を生成する複数のサブクラス(派生クラス)があります。これらのインスタンスは主にテキストの周りを囲むオブジェクトとして活用されます。
以下のサンプルコードで作成できる図形(サブクラスのインスタンス)の種類を確認しておきます。
# MATPLOTLIB_FANCY_BBOX_PATCH
# In[1]
import matplotlib.pyplot as plt
# Figureを設定
fig = plt.figure(figsize =(8, 6))
# Axesを追加
ax = fig.add_subplot(111)
# 目盛線を描画
ax.grid()
# bbox辞書リストを作成
box_style = [{"boxstyle" : "circle"},
{"boxstyle" : "darrow"},
{"boxstyle" : "larrow"},
{"boxstyle" : "rarrow"},
{"boxstyle" : "round"},
{"boxstyle" : "round4"},
{"boxstyle" : "roundtooth"},
{"boxstyle" : "sawtooth"},
{"boxstyle" : "square"}]
ax.text(0.1, 0.8, "Circle", size=16, bbox = box_style[0])
ax.text(0.4, 0.8, "Darrow", size=16, bbox = box_style[1])
ax.text(0.7, 0.8, "Larrow", size=16, bbox=box_style[2])
ax.text(0.1, 0.5, "Rarrow", size=16, bbox=box_style[3])
ax.text(0.4, 0.5, "Round", size=16, bbox=box_style[4])
ax.text(0.7, 0.5, "Round4", size=16, bbox=box_style[5])
ax.text(0.1, 0.2, "Roundtooth", size=16, bbox=box_style[6])
ax.text(0.4, 0.2, "Sawtooth", size=16, bbox=box_style[7])
ax.text(0.7, 0.2, "Square", size=16, bbox=box_style[8])

枠線のスタイル、網掛けの種類、塗り潰し/枠線の色などを設定することもできます。
# In[2]
# Figureを設定
fig = plt.figure(figsize =(5, 5))
# Axesを追加
ax = fig.add_subplot(111)
# 目盛線を描画
ax.grid()
# bboxの辞書作成
bdic = {"boxstyle" : "round",
# 枠線のスタイル
"linestyle" : "--",
# 枠線の太さ
"linewidth" : 3,
# 枠線の色
"edgecolor" : "darkblue",
# 網掛け模様
"hatch" : "+",
# 塗り潰しの色
"facecolor" : "lime",
}
ax.text(0.2, 0.5, "Python", size=50, bbox=bdic)

matplotlib.patches.FancyBboxPatchクラスのインスタンス引数
| 引数 | 記述方法 |
|---|---|
| alpha | float |
| color | color |
| edgecolor | color |
| facecolor | color |
| fill | bool |
| hatch | {“/”, “\”, “|”, “-“, “+”, “x”, “o”, “O”, “.”, “*”} |
| linestyle | {“-“, “–“, “-.”, “:”} |
| linewidth | float |
| url | str |
| visible | bool |
コメント