How could I format the bar labels to remove the scientific notation?
JavaScript
x
16
16
1
highest_enrollment = course_data.groupby(
2
"course_organization")["course_students_enrolled"].sum().nlargest(10)
3
4
ax = sns.barplot(x=highest_enrollment.index,
5
y=highest_enrollment.values,
6
ci=None,
7
palette="ch: s=.5, r=-.5")
8
9
ax.ticklabel_format(style='plain', axis="y")
10
11
plt.xticks(rotation=90)
12
13
ax.bar_label(ax.containers[0])
14
15
plt.show()
16
Advertisement
Answer
As already suggested by BigBen in the comment, you can pass fmt
parameter to matplotlib.axes.Axes.bar_label
; you can use %d
for integers:
JavaScript
1
17
17
1
import matplotlib.pyplot as plt
2
import seaborn as sns
3
import pandas as pd
4
5
highest_enrollment = pd.DataFrame({'class': ['A', 'B', 'C'],
6
'values': [30000000, 20000000, 10000000]})
7
8
ax = sns.barplot(data = highest_enrollment, x = 'class', y = 'values', palette="ch: s=.5, r=-.5")
9
10
ax.ticklabel_format(style='plain', axis="y")
11
12
plt.xticks(rotation=90)
13
14
ax.bar_label(ax.containers[0], fmt = '%d')
15
16
plt.show()
17