How to set font size of Matplotlib axis Legend?

后端 未结 7 1624
渐次进展
渐次进展 2020-12-02 10:19

I have a code like this:

import matplotlib.pyplot as plt
from matplotlib.pyplot import *
from matplotlib.font_manager import FontProperties

fontP = FontProp         


        
7条回答
  •  囚心锁ツ
    2020-12-02 10:58

    Inspired by the current top answer, I found a slightly more natural way to change the fontsizes in the legend. The fontsize argument sets the font size of each of the data labels, and the title_fontsize argument sets the fontsize of the title, if you give the legend a title.

    import matplotlib.pyplot as plt
    fig, ax = plt.subplots()
    ax.plot([0,1,2],[2,1,2],label='test_data (fs=12)')
    ax.legend(fontsize=12, title='TITLE (fs=30)',title_fontsize=30)
    

    Gives a figure like this:

提交回复
热议问题