はじめに
棒グラフ(ax.bar)や塗りつぶし(ax.fill_between)では、hatchを設定することで、さまざまな模様をつけることができる。ここでは、ax.fill_betweenを用いて、hatchで使用可能な模様の一覧を表示する。
また、hatchの模様の太さを変える方法についても説明する。
コード&解説
モジュールのインポートなど
バージョン
データの作成
lmfit.lineshapes の gaussianでガウス分布データを作成する。
ax.fill_betweenで任意のhatchを用いる関数
aはaxで、 hはhatchで,fcはfill_betweenのfacecolorとなっている。
hatchを変化させて、ax.fill_betweenをplot その1
hatch を [‘/’, ‘\\’, ‘|’, ‘-‘, ‘+’, ‘x’, ‘o’, ‘O’, ‘.’, ‘*’]として、plotした場合には、以下のようになる。

hatchを変化させて、ax.fill_betweenをplot その2
hatch を [‘//’, ‘\\\\’, ‘||’, ‘–‘, ‘++’, ‘xx’, ‘oo’, ‘OO’, ‘..’, ‘**’]として、plotした場合には、以下のようになる。

hatchを変化させて、ax.fill_betweenをplot その3
hatch を [‘/o’, ‘\\|’, ‘|*’, ‘-\\’, ‘+o’, ‘x*’, ‘o-‘, ‘O|’, ‘O.’, ‘*-‘]として、plotした場合には、以下のようになる。

まとめて表示
その1からその3をまとめて表示すると以下のようになる。

hatchの太さを細くする場合
plt.rcParams[“hatch.linewidth”]=.5として、hatch.linewidthを細くする。

hatchの太さを太くする場合
plt.rcParams[“hatch.linewidth”]=3とすれば、太いhatchとなる。

参考
matplotlib.pyplot.fill_between — Matplotlib 3.5.0 documentation
Hatch style reference — Matplotlib 3.5.0 documentation
コメント