我正在尝试创建一个分组的条形图,以使我可以按国家比较三个变量。我已经做到了,但是每个国家的每个变量都有一个不同的标签
但是,我希望葡萄牙的颜色和其他国家/地区的颜色相同。 这是我的代码:
data_bar = []
for country in countries:
df_bar = df.loc[(df['Country'] == country)]
x1= ['Cost of Living']
x2 = ['Groceries']
x3 = ['Rent']
y_bar1 = df_bar['Cost of living']
y_bar2 = df_bar['Groceries']
y_bar3 = df_bar['Rent']
data_bar.append(dict(type='bar', x=x1, y=y_bar1,
name=country))
data_bar.append(dict(type='bar', x=x2, y=y_bar2,
name=country))
data_bar.append(dict(type='bar', x=x3, y=y_bar3,
name=country))
layout_bar = dict(title=dict(text='How expensive is it to live here?'), barmode='group',
template="plotly_dark")
我意识到这种情况的发生是因为我在每个追加中都添加了name = country,但这是它识别它们的唯一方法。谁能帮我吗?