简体   繁体   English

有没有办法在 Plotly Express 中使用十六进制颜色代码自定义 color_continuous_scale 参数?

[英]Is there a way to customize the color_continuous_scale argument with hex color code in Plotly Express?

I've searched around for a while now and I am trying to customize the color scale by hex color code, but I could not find a valid way to do it.我已经搜索了一段时间,我正在尝试通过十六进制颜色代码自定义颜色比例,但我找不到有效的方法来做到这一点。 Is the default preset color sales the only option for us?默认预设颜色销售是我们唯一的选择吗? This is for a map generated by plotly's mapbox API.这是针对由 plotly 的 mapbox API 生成的 map。

I have gone through their documentation here: https://plotly.com/python/styling-plotly-express/我在这里浏览了他们的文档: https://plotly.com/python/styling-plotly-express/

Any comment or tips would be greatly appreciated!任何评论或提示将不胜感激!

Figured it out finally so I'll answer myself, setting a custom color scale like below then assigning it to the argument would work:终于想通了,所以我会回答自己,设置如下所示的自定义色阶,然后将其分配给参数会起作用:

colorscale = [
[0, 'rgb(38, 53, 113)'], 
[0.5, 'rgb(57, 162, 225)'],
[1, 'rgb(234, 32, 41)']
]

...and then in the argument:color_continuous_scale = colorscale ...然后在参数中:color_continuous_scale = colorscale

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM