Python data visualization: how to display data on top of a histogram

Show the rendering first.
insert image description here
Use the new bar_label function in matplotlib version 3.4. The specific code is as follows:

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

sns.set_theme(style="whitegrid")
sns.set_style('darkgrid')
sns.set(rc={
    
    'figure.figsize':(9,4.5)}) # 设置图片宽高

# 准备数据
x = ['c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'c9']
y = [230, 856, 309, 500, 10000, 5000, 205, 366, 1484]
pd = pd.DataFrame({
    
    "Column": x, "Number": y})

# 绘图
fig = sns.barplot(data=pd, x="Column", y="Number")
fig.bar_label(fig.containers[0]);  # 只有一组柱状图的情况

plt.show()

Multiple histogram scenarios are visible:

How to display custom values on a bar plot

Guess you like

Origin blog.csdn.net/weixin_45943887/article/details/126016447