我正在尝试用Python构建一个带有情节的堆叠条形图。
我的目标是为哥本哈根的每个城市地区做一个酒吧,那里堆放着不同的树木类型。我可以运行我的代码直到第10棵树,在此之后,我得到一个索引错误:
单个位置索引器越界
当我只为10棵树或更少的树木做这件事时,一切看起来都很好。
我的代码如下所示
## df is a dataframe where each row is a tree type
## and each column a city district
x = df.columns ## district names
trees = df.index ## tree names
for i in range(0,len(trees)):
if i == 0:
fig = go.Figure(go.Bar(x=x, y=df.iloc[:,i].values, name = trees[i]))
else:
fig.add_trace(go.Bar(x=x, y=df.iloc[:,i].values, name = trees[i]))
fig.update_layout(barmode='stack')
fig.show()
我似乎无法弄清楚这个错误是什么。
慕哥6287543
相关分类