首页 > 解决方案 > 如何在 Python Pandas 中增加 countplot 的字体大小?

问题描述

我有以下代码创建的计数图:

plt.figure(figsize = (20,5))
ax=sns.countplot(x = "CompanyName", data = data)
ax.set_title("Number of passengers based on gender", fontsize = 20)
plt.xlabel("CompanyName",fontsize=17)
plt.ylabel("count", fontsize=17)
for p in ax.patches:
    ax.annotate(f'\n{p.get_height()}', (p.get_x()+0.2, p.get_height()), color='black', size=15, ha="center")

该图如下所示: 在此处输入图像描述

我的问题是:如何增加对 y 轴值的描述。我想要例如“Alfa-romeo”、“Audi”、“Bmw”等等,用更大的字体书写。您可以更改我上面的代码以实现它吗?

标签: pythonpandasfontsseaborn

解决方案


你可以试试这个:

#to increase y ticks size
plt.yticks(size=50)

#to increase x ticks 
plt.xticks(size=50)

推荐阅读