'''显示数据'''
def showme(self,x,sales):
# 导入绘图模块import matplotlib.pyplot as plt
# 构建数据
#sales = [7125,12753,13143,8635]
# 中文乱码的处理
plt.rcParams['font.sans-serif'] =['SimHei']
plt.rcParams['axes.unicode_minus'] = False
#x = ['苹果','香蕉','梨','猕猴桃']
# 绘图 水平
plt.barh(range(len(x)), sales, 0.4,color='r', alpha = 0.8)
# 添加轴标签
#plt.ylabel('数量')
# 添加标题
plt.title('2021rs')
# 添加刻度标签
plt.yticks(range(len(x)),x)
# 设置Y轴的刻度范围
#plt.xlim([5000,15000])
# 为每个条形图添加数值标签
for x,y in enumerate(sales):
plt.text(y+0.2,x,'%s' %y,va='center')
# 显示图形
plt.show()
参考:
matplotlib柱状图上方显示数据_Python数据可视化之Matplotlib实现各种图表!_Hu??的博客-优快云博客
首先要有x 和y两个数组数据
x = []
y = []
for m in result:
print(m)
x.append(m[0])
y.append(m[1])
self.showme(x,y)
数组的赋值是append函数,不能使用x[i]=1 i++这种
显示图片