How to customize the color_continuous_scale in plotly?

我想用plotly的热力图强调某个区间数据, 比如:下图,我想让显示黄色的取值区间为146-317, 或者说当取值范围在146-317时显示黄色,我该咋做呢?

I want to use plotly’s heat map to emphasize a certain range of data, for example: in the figure below, I want to display the value range of yellow as 146-317, or display yellow when the value range is 146-317, what should I do?

Hi @jumbo
welcome to the community and thank you for your question.
I don’t think you can be so specific about where yellow starts and ends (146-317), especially because your using continuous color scales. However, trying adding this parameter to your figure. Maybe that will get you close. Note that the integers inside the list have to be from 0 to 1.

color_continuous_scale=[[0, 'red'], [0.5, 'yellow'], [1, 'blue']]

You can read more about color scaling in the docs.

我读过 color scaling in the docs了,没有找到我想要的, 我这个需求👆🏻, 应该能实现呀? 就像这样👇🏻:

I have read color scaling in the docs, but I can’t find what I want, my requirement :point_up_2:t2:, should be able to achieve it? Like this :point_down: :point_down::

To map your data ranges to prescribed colors, see this thread Colors for discrete ranges in heatmaps

and this notebook: b'Heatmap with a discrete colorscale | empet | Plotly'

If you want to use colors from an available color continuous scale see also the function get_color_for_val I defined in this thread: Hover background color on scatter 3d

太棒了! 谢谢大神了!

Great! Thanks