我有这样的代码:
import matplotlib.pyplot as plt
from matplotlib.pyplot import *
from matplotlib.font_manager import FontProperties
fontP = FontProperties()
fontP.set_size('xx-small')
fig=plt.figure()
ax1=fig.add_subplot(111)
plot([1,2,3], label="test1")
ax1.legend(loc=0, ncol=1, bbox_to_anchor=(0, 0, 1, 1),
prop = fontP,fancybox=True,shadow=False,title='LEGEND')
plt.show()
Run Code Online (Sandbox Code Playgroud)

从图中可以看出,Fontsize中的设置不会影响Legend Title字体大小.
如何将图例标题的字体大小设置为较小的尺寸?
我想更改我的图例标题的字体大小matplotlib。这是我的第一个猜测
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca()
ax.plot(range(10))
lg = ax.legend(['test entry'],title='test')
lg.set_title(fontsize='large')
plt.show()
Run Code Online (Sandbox Code Playgroud)
这会产生错误
File "test.py", line 6, in <module>
lg.set_title(fontsize='large')
TypeError: set_title() got an unexpected keyword argument 'fontsize'
Run Code Online (Sandbox Code Playgroud)
我也尝试过
lg = ax.legend(['test entry'],title='test',title_fontsize='large')
Run Code Online (Sandbox Code Playgroud)
产生
self.legend_ = mlegend.Legend(self, handles, labels, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'title_fontsize'
Run Code Online (Sandbox Code Playgroud)