我有一张美国 map ,正在用普洛特利快报绘制总统选举的获胜优势.我希望获胜的利润率为0显示为白色,并将比例发散为红色/蓝色.但是,COLOR_CONTINUOUS_SCALE关键字参数的取值范围为0-1,并且每次选举的获胜幅度为0-1的范围各不相同.
有什么解决办法可以让我将0定义为白色,将极端定义为红色/蓝色吗?
我曾试图将获胜优势0转换为介于0和1之间的分数,但这在每个选举周期都会发生变化.
fig = px.choropleth(merged,
locationmode='USA-states',
locations='state_po',
animation_frame='year',
color='R_margin_x',
color_continuous_scale=[(0, 'blue'),
(merged['R_margin_x'].min()/(merged['R_margin_x'].min()-merged['R_margin_x'].max()), 'white'),
(1, 'red')],
scope='usa')
fig.show()
数据帧的形式为
party_simplified state_po year DEMOCRAT LIBERTARIAN OTHER REPUBLICAN D_pct_x L_pct_x O_pct_x R_pct_x R_margin_x D_pct_y L_pct_y O_pct_y R_pct_y R_margin_y R_lean
0 AK 2008 123594.0 1589.0 7173.0 193841.0 37.889374 0.487129 2.198978 59.424520 21.535146 52.761558 0.388418 1.488455 45.361569 -7.39999 28.935135
1 AL 2008 813479.0 NaN 19794.0 1266546.0 38.740434 NaN 0.942653 60.316913 21.576479 52.761558 0.388418 1.488455 45.361569 -7.39999 28.976468
2 AR 2008 422310.0 4776.0 21514.0 638017.0 38.864660 0.439529 1.979906 58.715904 19.851245 52.761558 0.388418 1.488455 45.361569 -7.39999 27.251234
3 AZ 2008 1034707.0 12555.0 16102.0 1230111.0 45.115251 0.547423 0.702079 53.635248 8.519997 52.761558 0.388418 1.488455 45.361569 -7.39999 15.919987
4 CA 2008 8274473.0 67582.0 208064.0 5011781.0 61.012638 0.498323 1.534180 36.954859 -24.057780 52.761558 0.388418 1.488455 45.361569 -7.39999 -16.657790