小编use*_*206的帖子

matplotlib堆积条形图AssertionError:不兼容的大小:参数'bottom'必须是长度3或标量

我需要拿出一张不同列表的条形图

import math
import numpy as np
import matplotlib.pyplot as plt


month=["dec-09","jan","feb"]
n=len(month)
kitchen=[57.801,53.887,49.268]
laundry=[53.490,56.568,53.590]
air=[383.909,395.913,411.714]
other=[519.883,483.293,409.956]

ind=np.arange(n)
width=0.35

p1=plt.bar(ind,kitchen,width,color="cyan")
p2=plt.bar(ind,laundry,width,color="red",bottom=kitchen)
p3=plt.bar(ind,air,width,color="green",bottom=kitchen+laundry)
p4=plt.bar(ind,other,width,color="blue",bottom=kitchen+laundry+air)

plt.ylabel("KWH")
plt.title("winter")
plt.xticks(ind+width/2,("dec-09","jan","feb"))
plt.show()
Run Code Online (Sandbox Code Playgroud)

它只是一个简单的代码,我想把它们叠加但我遇到了一个错误,我不知道该怎么办

p3=plt.bar(ind,air,width,color="green",bottom=kitchen+laundry)
File "C:\Python33\lib\site-packages\matplotlib\pyplot.py", line 2515, in bar
ret = ax.bar(left, height, width=width, bottom=bottom, **kwargs)
File "C:\Python33\lib\site-packages\matplotlib\axes.py", line 5007, in bar
nbars)
AssertionError: incompatible sizes: argument 'bottom' must be length 3 or scalar
Run Code Online (Sandbox Code Playgroud)

python matplotlib

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

matplotlib ×1

python ×1