【问题标题】:How to increase the font size on the countplot in Python Pandas?如何在 Python Pandas 中增加 countplot 的字体大小?
【发布时间】:2020-11-25 01:35:11
【问题描述】:

我有下面这段代码创建的计数图:

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”等等,用更大的字体书写。你能改变我上面的代码来实现它吗?

【问题讨论】:

  • plt.xticks(sorted(data.CompanyName.unique()), fontsize=22)。你可以用任何东西改变22。不过,您可能需要旋转标签
  • 添加代码后出现这样的错误:ConversionError: 无法将值转换为轴单位
  • 试试这个:plt.rc('xtick',labelsize=22)
  • 可以增加图大小

标签: python pandas fonts seaborn


【解决方案1】:

你可以试试这个:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-03
    • 2014-12-15
    • 2010-10-10
    • 2015-12-05
    • 2012-08-11
    • 2017-10-07
    • 2014-09-22
    • 2012-11-07
    相关资源
    最近更新 更多