#coding=utf-8
import numpy as np
import matplotlib.pyplot as plt
x=np.arange(10)
y1=(1-x/float(10))*np.random.uniform(0.5,1,10)
y2=(1-x/float(10))*np.random.uniform(0.5,1,10)
plt.bar(x,y1,facecolor='#9999ff',edgecolor='white')
plt.bar(x,-y2,facecolor='#ff9999',edgecolor='white')
a=zip(x,y1)
b=zip(x,y2)
for x,y in a:
plt.text(x,y+0.1,'%.2f'%y,ha='center',va='bottom')
#为直方图添加注释标签
for x,y in b:
plt.text(x,-y-0.1,'%.2f'%y,ha='center',va='bottom')
#为直方图添加注释标签
#设置柱状图存放x,y数据
plt.xlim((-1,10))
plt.ylim((-1,1.2))
#设置x,y轴范围
plt.xticks(())
plt.yticks(())
#不显示x,y轴刻度
plt.show()