【发布时间】:2022-02-06 21:04:42
【问题描述】:
我正在使用this kaggle dataset 执行我的数据分析。
我将'course_students_enrolled' 列值转换为整数。
当我绘制学生人数最多的课程时,我得到一个数字,其中代表 1M 以上值的条形标签出现在公式中,如1.3e+06,而不是显示完整数字。图表上方的数字也是如此。
这是我的情节代码:
popularity_filt = (main_df['course_students_enrolled'].sort_values(ascending=False))
most_pop_courses = main_df.iloc[popularity_filt.index][:10]
course_titles = most_pop_courses['title'].to_list()
data = most_pop_courses[['title','course_students_enrolled']]
sns.set_context(font_scale=3, rc={'font.size':12, 'axes.labelsize':20})
sns.set_style('darkgrid')
palette = sns.color_palette(palette="Greens_d", n_colors=len(data))
plt.figure(figsize=(12,6))
ax = sns.barplot(x='title', y='course_students_enrolled', data=data, palette=np.array(palette[::-1]));
ax.set_xticklabels(course_titles, rotation=40, ha='right')
ax.bar_label(ax.containers[0]);
plt.show()
有没有办法显示完整的数字?
【问题讨论】:
-
ax.bar_label(ax.containers[0], fmt='%.0f')
标签: python matplotlib seaborn bar-chart