【发布时间】:2019-06-08 12:36:52
【问题描述】:
我正在尝试从我的数据创建堆积条形图并不断收到错误消息
ValueError:形状不匹配:对象不能广播到单个 形状
这是我写的相关代码:
num = list(yearly_posts.index)
barWidth = 0.50
plt.bar(num,yearly_status.values, color='#b5ffb9',edgecolor='white',width=barWidth)
plt.bar(num,yearly_posts.values, color='#f9bc86',edgecolor='white',width=barWidth)
这是我的数据样本
#yearly_status table
year
2009 85
2010 86
2011 188
2012 274
2013 240
2014 171
2015 132
2016 22
2017 18
2018 13
dtype: int64
#yearly_posts table
year
2009 8
2010 19
2013 19
2014 40
2015 13
2016 20
2017 27
2018 17
dtype: int64
【问题讨论】:
-
yearly_status.values和yearly_posts.values的大小不同,但您只使用一个num(大小为yearly_posts)。您可能应该将第一次plt.bar调用中的num更改为list(yearly_status.index) -
@Bart 啊哈,明白了,谢谢
标签: python matplotlib data-science