这个问题的说明并不适用于Seaborn FacetPlots。可能有方法可以实现相同的效果吗?
FacetGrid的图例不是坐标轴的一部分,而是FacetGrid对象的一部分。该图例仍然是一个标准的Matplotlib图例,可以像其他图例一样进行操作。
plt.setp(g._legend.get_title(), fontsize=20)
在调用创建facetgrid对象的函数后,g将是您的facetgrid对象。
plt.legend(fontsize='x-large', title_fontsize='40')
https://matplotlib.org/api/_as_gen/matplotlib.pyplot.legend.html
这可能取决于您使用的matplotlib版本。我正在使用2.2.3,它具有fontsize
参数,但没有title_fontsize
。
就像链接的答案中所述,您可以使用setp
来设置属性(在这种情况下是图例的字体大小)。
与链接的问题唯一的区别是您需要为FacetGrid的每个轴执行此操作。
g = FacetGrid( ... )
for ax in g.axes.flat:
plt.setp(ax.get_legend().get_texts(), fontsize=22) # for legend text
plt.setp(ax.get_legend().get_title(), fontsize=32) # for legend title
AttributeError: 'FacetGrid' object has no attribute 'get_legend'
。在链接的回答中的评论中也提到了这一点。 - tangysns.factorplot
,需要执行ax[0].get_legend()...
。 - tangyAttributeError: 'NoneType' object has no attribute 'get_texts'
- upuil