#!/usr/bin/python
# coding: utf-8
import matplotlib.pyplot as plt
#name_list = ['0', 'lambda=0.05', 'lambda=0.1', 'lambda=0.5']
#num_list = [52.4, 57.8, 59.1, 54.6]
num_list=[13, 5, 8, 13, 516, 86, 5, 4, 21, 1]
name_list= [35, 41, 43, 45, 46, 50, 51, 55, 56, 60]
#plt.plot(name_list,num_list)
#rects=plt.bar(range(len(num_list)), num_list, color='rgby')
rects=plt.bar(name_list, num_list, color='rgby')
# X轴标题
# X轴标题
index=[35, 41, 43, 45, 46, 50, 51, 55, 56, 60]
#index=[float(c)+0.4 for c in index]
print("index:",index)
plt.ylim(ymax=600, ymin=0)
#plt.xticks]]](index,name_list)
plt.ylabel("number") #X轴标签
i=0
for rect in rects:
    i=i+1
    height = rect.get_height()
    print(rect,height)
    print(rect.get_x() , rect.get_width() / 2)
    plt.text(str(rect.get_x() + rect.get_width() / 2), height, str(height), ha='center', va='bottom')
    #plt.text(str(index[i]), height, str(height), ha='center', va='bottom')
    #i=i+1
print("i:",i)
#plt.pause(15)  #显示秒数
plt.show()
#plt.hide()
#plt.pause(15)  #显示秒数

 

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐