首页 > 其他分享 >09Bar柱状图

09Bar柱状图

时间:2023-01-31 20:44:38浏览次数:34  
标签:plt 09Bar Y1 柱状图 np ha Y2

import matplotlib.pyplot as plt
import numpy as np

n=12
X=np.arange(n)
Y1=(1-X/float(n))*np.random.uniform(0.5,1.0,n)
Y2=(1-X/float(n))*np.random.uniform(0.5,1.0,n)

plt.bar(X,+Y1,facecolor='#9999ff',edgecolor='white')
plt.bar(X,-Y2,facecolor='#ff9999',edgecolor='white')

for x,y in zip(X,Y1):
    #ha:horizontal alignment
    plt.text(x+0.1,y+0.005,'%.2f'%y,ha='center',va='bottom')

for x,y in zip(X,Y2):
    #ha:horizontal alignment
    plt.text(x+0.1,-y-0.005,'%.2f'%y,ha='center',va='top')

plt.xlim((-1,n))
plt.ylim((-1.5,1.5))


plt.show()

image-20230131173323153

标签:plt,09Bar,Y1,柱状图,np,ha,Y2
From: https://www.cnblogs.com/lyc2001/p/17080713.html

相关文章