matplotlib_200730系列---6、Bar 柱状图
一、总结
一句话总结:
柱状图使用非常简单,就是bar方法:plt.bar(X,+Y1,facecolor="#9999ff",edgecolor="white")
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, y+0.05, '%.2f' %(y),ha='center',va='bottom') for x,y in zip(X,Y2): # ha: horizontal alignment plt.text(x, -y-0.20, '%.2f' %(y),ha='center',va='bottom')
二、Bar 柱状图
博客对应课程的视频位置:
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, y+0.05, '%.2f' %(y),ha='center',va='bottom') for x,y in zip(X,Y2): # ha: horizontal alignment plt.text(x, -y-0.20, '%.2f' %(y),ha='center',va='bottom') plt.xlim(-0.5,n) plt.xticks(()) plt.ylim(-1.25,1.25) plt.yticks(())