我设法从2个数据框中创建2个子图,但是似乎没有保留我选择的颜色。这是我的代码:
Worst_20=Worst_deathrate.head(20)
Best_20=Best_recoveredrate.head(20)
fig=make_subplots(rows=1,cols=2,subplot_titles=['Worst Death Rate','Best Recovered Rate'],
specs=[[{"type": "bar"}, {"type": "bar"}]])
fi1=px.bar(Worst_20,x=Worst_20.index ,y='death_rate',color=np.log(Worst_20['death_rate']),
color_continuous_scale=px.colors.sequential.Agsunset)
fig2=px.bar(Best_20,x=Best_20.index,y=Best_20['recovered_rate'],color=np.log(Best_20['recovered_rate']),
color_continuous_scale=px.colors.sequential.Tealgrn)
fig.add_trace(fig1['data'][0],row=1,col=1)
fig.add_trace(fig2['data'][0],row=1,col=2)
fig.update(layout_coloraxis_showscale=True)
fig.show()
在下方,您可以看到,结果未按设定显示:
答案 0 :(得分:0)
真是痛苦。您可能想尝试的是这样的东西:
fig.update_layout(coloraxis_autocolorscale=False, coloraxis_colorscale=['blue','lightblue','yellow','orange','darkorange','red'])
关键部分是 coloraxis_autocolorscale = False ,它会禁用默认模板的色标设置。然后,您可以尝试为两个子图设置一些通用自定义色阶。我找不到设置2种不同音阶的方法。