seaborn 绘图展示数据标签
y= data11['总数']
sns.set(style='darkgrid',context='talk',font='SimHei')
plt.subplots(figsize= (18,10))
plt.title('回收数量统计')
ax1 =sns.barplot(data11['型号'],data11['总数'],palette='pastel')
ax1.set_xticklabels(ax1.get_xticklabels(), rotation=-90)
for index in range(len(y)):
ax1.text(index,y.values[index]+1,'%d'%y.values[index],ha='center')
不必纠结柱状图的x轴坐标, for 循环,从0 开始标注
import seaborn as sns
import numpy as np
import pandas
sns.set(style='ticks', color_codes=True)
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
# 能够识别中文
data = pandas.read_csv('./tips.csv')
# 'F:\\tips.csv' 文件存放的路径
# 读取文件数据
grouped_values = data.groupby('day').sum().reset_index()
# 按照day进行数据分组,得到一个按day分组汇总后的数据
pal = sns.color_palette('Greens_d', len(grouped_values))
rank = grouped_values['total_bill'].argsort().argsort()
g = sns.barplot(x='day', y='tip', data=grouped_values, palette=np.array(pal[::-1])[rank])
for index, row in grouped_values.iterrows():
g.text(row.name, row.tip, round(row.total_bill, 2), color='black', ha='center')
plt.show()