如何摆脱 matplotlib 中条形标签上的科学记数法?
How to get rid of scientific notation on bar labels in matplotlib?
如何格式化条形标签以删除科学记数法?
highest_enrollment = course_data.groupby(
"course_organization")["course_students_enrolled"].sum().nlargest(10)
ax = sns.barplot(x=highest_enrollment.index,
y=highest_enrollment.values,
ci=None,
palette="ch: s=.5, r=-.5")
ax.ticklabel_format(style='plain', axis="y")
plt.xticks(rotation=90)
ax.bar_label(ax.containers[0])
plt.show()
正如 BigBen 在评论中所建议的,您可以将 fmt
参数传递给 matplotlib.axes.Axes.bar_label
;您可以使用 %d
表示整数:
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
highest_enrollment = pd.DataFrame({'class': ['A', 'B', 'C'],
'values': [30000000, 20000000, 10000000]})
ax = sns.barplot(data = highest_enrollment, x = 'class', y = 'values', palette="ch: s=.5, r=-.5")
ax.ticklabel_format(style='plain', axis="y")
plt.xticks(rotation=90)
ax.bar_label(ax.containers[0], fmt = '%d')
plt.show()
如何格式化条形标签以删除科学记数法?
highest_enrollment = course_data.groupby(
"course_organization")["course_students_enrolled"].sum().nlargest(10)
ax = sns.barplot(x=highest_enrollment.index,
y=highest_enrollment.values,
ci=None,
palette="ch: s=.5, r=-.5")
ax.ticklabel_format(style='plain', axis="y")
plt.xticks(rotation=90)
ax.bar_label(ax.containers[0])
plt.show()
正如 BigBen 在评论中所建议的,您可以将 fmt
参数传递给 matplotlib.axes.Axes.bar_label
;您可以使用 %d
表示整数:
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
highest_enrollment = pd.DataFrame({'class': ['A', 'B', 'C'],
'values': [30000000, 20000000, 10000000]})
ax = sns.barplot(data = highest_enrollment, x = 'class', y = 'values', palette="ch: s=.5, r=-.5")
ax.ticklabel_format(style='plain', axis="y")
plt.xticks(rotation=90)
ax.bar_label(ax.containers[0], fmt = '%d')
plt.show()