相关疑难解决方法(0)

如何设置Matplotlib轴Legend的字体大小?

我有这样的代码:

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字体大小.

如何将图例标题的字体大小设置为较小的尺寸?

python matplotlib legend font-size

49
推荐指数
8
解决办法
7万
查看次数

更改 matplotlib 中图例的标题字体大小

我想更改我的图例标题的字体大小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)

python matplotlib legend

3
推荐指数
1
解决办法
8571
查看次数

标签 统计

legend ×2

matplotlib ×2

python ×2

font-size ×1