条形图上方显示标签
数据降序排列:data = data.sort_values(by=[‘项目数量’], ascending=True)
取消x,y轴:plt.axis(‘off’)
添加灰色底色:color=’#F5F5F5’
标签、数据上方显示:for循环
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
data = pd.read_excel(r"C:\Users\10069\Desktop\2.1招标单位排行榜.xlsx")
data = data.sort_values(by=['项目数量'], ascending=True) # 降序排列
num = data['项目数量'][0] # 取最大数值
x_label = np.array(data['招标单位'])
y = np.array(data['项目数量'])
x_value = np.arange(len(x_label)) # 标签个数
fig = plt.figure(figsize=(6,6))
plt.axis('off') # 取消轴
plt.barh(x_value,color='#F5F5F5',height=0.3,width=num,align='center') # 添加灰色底色
plt.barh(x_value,color='#0099DC',height=0.3,width=y,align='center') # 蓝色条形图
for a,b,label in zip