LoginSignup
1
5

More than 3 years have passed since last update.

matplotlibを使ったplot系モジュールが作成したグラフの見切れラベルを回避する方法

Posted at

はじめに

内部でmatplotlibを使っているグラフプロット系のメソッドが出力したグラフを保存してみると、軸ラベルが見切れてしまう場合がある。
メソッド内でレイアウト設定がされているため、調節するのも一苦労だが、そこをよしなに調整する方法を書き記しておく。

やり方

pylab(matplotlib.pylabでも可)のtight_layoutメソッドを呼び出せばよい。

グラフ内の軸ラベルやメモリラベルがうまく出力できるようにグラフレイアウトが変更される。

以下は、shapモジュールのsummary_plotによる例。

shapのsummary_plotでの例
shap.summary_plot(shap_values, X, show=False)
pylab.tight_layout()
plt.savefig('./shap.png')

参考

1
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
5