はじめに
matplotlibのmpl_toolkits.axisartistを用いて、軸の先端を矢印に変える方法について説明する。
コード

解説
モジュールのインポート
figの作成
ax = SubplotZero(fig, 111)のようにSubplotZeroでグラフを作成する必要がある。SubplotZeroはmatplotlib.axes._subplots.AxesZeroSubplotである。
軸の設定
上と右の軸をset_visible(False)で消す。
下と左の軸に.set_axisline_style(“-|>”)で軸の先端を矢印とする。
矢印のスタイルを変える

set_axisline_style(“->”)とすることで塗りつぶし矢印ではなく、普通の矢印となる。
先端の大きさを変える

set_axisline_style(“-|>”, size=3)でサイズを変更できる。
line.set_facecolor(“g”) で塗りつぶし矢印の色を変えられる。
軸、目盛り、目盛りラベルの色を変える

上記のようにすることで矢印、軸、目盛り、目盛りラベルの色を変えることができる。
コードをダウンロード(.pyファイル) コードをダウンロード(.ipynbファイル)参考
Axis line styles — Matplotlib 3.10.0 documentation

What is SubplotZero? (documentation lacking)
My questionI would like to know what matplotlib's SubplotZero() function does, knowing that it is not referenced in matp...

How to increase the arrow size of axis_artist in matplotlib
I play around with the example from here. I want to increase the size of the arrows at the ends of x-axis and y-axis. I ...
コメント