はじめに
matplotlibのax.legend()で表示できる凡例で、凡例ボックス内の凡例表示位置を調整する方法について説明する。
コード&解説
モジュールのインポートなど
バージョン
データの生成
判例box内で左に寄せて表示
ax.legend()でax.legend(alignment=”left”)とすると以下のようになる。
![](https://sabopy.com/wp/wp-content/uploads/2023/01/legend_alignment1.jpg)
判例box内の中央に表示
ax.legend()でax.legend(alignment=”center”)とすると以下のようになる。
![](https://sabopy.com/wp/wp-content/uploads/2023/01/legend_alignment2.jpg)
判例box内で右に寄せて表示
ax.legend()でax.legend(alignment=”right”)とすると以下のようになる。
![](https://sabopy.com/wp/wp-content/uploads/2023/01/legend_alignment3.jpg)
参考
What's new in Matplotlib 3.6.0 (Sep 15, 2022) — Matplotlib 3.9.1 documentation
コメント