用线性数据画柱状图
1
plt.figure() 2 xvals = range(len(linear_data)) 3 plt.bar(xvals, linear_data, width = 0.3) 4 5 new_xvals = [] 6 7 # 创建new_xvals使横坐标向右移动0.3,用平方数据画红色的柱状图 8 for item in xvals: 9 new_xvals.append(item+0.3) 10 11 plt.bar(new_xvals, exponential_data, width = 0.3 ,color='red') 12 13 from random import randint 14 linear_err = [randint(0,15) for x in range(len(linear_data))] 15 16 # 用随机的误差值来画新的误差坐标 17 plt.bar(xvals, linear_data, width = 0.3, yerr=linear_err)

1 #堆积条形图
2 plt.figure()
3 xvals = range(len(linear_data))
4 plt.bar(xvals, linear_data, width = 0.3, color='b')
5 plt.bar(xvals, exponential_data, width = 0.3, bottom=linear_data, color='r')

 

 

1 # 水平的堆积条形图
2 plt.figure()
3 xvals = range(len(linear_data))
4 plt.barh(xvals, linear_data, height = 0.3, color='b')
5 plt.barh(xvals, exponential_data, height = 0.3, left=linear_data, color='r')

 

posted on 2018-03-09 19:41  郑哲  阅读(192)  评论(0编辑  收藏  举报