import numpy as np import matplotlib.pyplot as plt x= [1,2,3,4,5,6,7,8] #[1]X坐标点 y= [2,3,4,6,2,3,8,6] plt.figure() plt.subplot() data = np.array([[3,3,3,15,3,3,3,10], #[1]蓝色y坐标值 [2,6,2,3,2,9,14,2], #[2]红色y坐标值 [4,3,9,4,12,4,21,4], #[3]绿色y坐标值 [4,14,6,13,4,4,21,4]]) #[4]灰色y坐标值 index = np.arange(data.shape[1]) color_index= ['r','g','b','y'] for i in range(4): j = i+1 #index+2:是起始坐标点 #width是bar的宽度 plt.bar(index+2,data[i],width=0.7,color=color_index[i],bottom=np.sum(data[:i],axis=0)) plt.show()
【Python_Demo_5】Python中条形重叠直方图的绘制
猜你喜欢
转载自blog.csdn.net/maweifei/article/details/80343814
今日推荐
周排行