matplotlib.pyplot で凡例のフォントサイズを変更する方法 質問する

matplotlib.pyplot で凡例のフォントサイズを変更する方法 質問する

簡単な質問です。凡例のサイズをmatplotlib.pyplot小さくしたい(つまり、テキストを小さくしたい)のですが。使用しているコードは次のようになります。

plot.figure()
plot.scatter(k, sum_cf, color='black', label='Sum of Cause Fractions')
plot.scatter(k, data[:, 0],  color='b', label='Dis 1: cf = .6, var = .2')
plot.scatter(k, data[:, 1],  color='r',  label='Dis 2: cf = .2, var = .1')
plot.scatter(k, data[:, 2],  color='g', label='Dis 3: cf = .1, var = .01')
plot.legend(loc=2)

ベストアンサー1

キーワードを調整することで、凡例のフォント サイズを個別に設定できますprop

plot.legend(loc=2, prop={'size': 6})

matplotlib.font_manager.FontPropertiesこれはプロパティに対応するキーワードの辞書を受け取ります。凡例のドキュメント:

キーワード引数:

prop: [ None | FontProperties | dict ]
    A matplotlib.font_manager.FontProperties instance. If prop is a 
    dictionary, a new instance will be created with prop. If None, use
    rc settings.

バージョン1.0以降では、1.2.1、キーワードを使用しますfontsize

おすすめ記事