條形圖_一組數據
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
N=5
y=[20,10,30,25,15]
index = np.arange(N)
#p1=plt.bar(index,y,width=0.5,color='b') #條形圖 left昨天橫座標 高度height color爲顏色,width爲寬度 垂直
plt.barh(index,y,width=0.5,color='b')#s水平直方圖
p1=plt.barh(
plt.show()
條形圖_兩組數據
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
index = np.arange(4)
sales_BJ=[52,55,63,53]
sales_SH=[44,66,55,41]
bar_width=0.3
plt.bar(index,sales_BJ,bar_width,color='b') #sales_BJ直方圖
plt.bar(index+bar_width,sales_SH,bar_width,color='r') #疊加sales_SH的直方圖(主要是加一個bar_width)圖1
#
plt.bar(index,sales_SH,bar_width,color='r',bottom=sales_BJ) #疊加sales_SH的層疊圖 圖2
plt.show()
圖1
圖2blog