How to set font size of Matplotlib axis Legend? How to set font size of Matplotlib axis Legend? python python

How to set font size of Matplotlib axis Legend?


This is definitely an old question, but was frustrating me too and none of the other answers changed the legend title fontsize at all, but instead just changed the rest of the text. So after banging my head against the matplotlib documentation for awhile I came up with this.

legend = ax1.legend(loc=0, ncol=1, bbox_to_anchor=(0, 0, 1, 1),           prop = fontP,fancybox=True,shadow=False,title='LEGEND')plt.setp(legend.get_title(),fontsize='xx-small')

As of Matplotlib 3.0.3, you can also set it globally with

plt.rcParams['legend.title_fontsize'] = 'xx-small'


Here is how to change the fontsize of the legend list and/or legend title:

legend=plt.legend(list,loc=(1.05,0.05), title=r'$\bf{Title}$') #Legend: list, location, Title (in bold)legend.get_title().set_fontsize('6') #legend 'Title' fontsizeplt.setp(plt.gca().get_legend().get_texts(), fontsize='12') #legend 'list' fontsize


Banged my head against it too, here is another more flowing way of doing it:

leg = ax.legend()leg.set_title('A great legend',prop={'size':14})