Functions to map floats to RGB values
It would be useful if Plotly exposed functions to map floats, e.g. values in [0,1], to corresponding RGB strings formatted as 'rgb(255, 0, 0)'. There are lots of use cases for this. For example, if you want to plot a network where each edge is colored according to a weight between 0 and 1 using a continuous color scale. The only way I know to do this right now is to make a separate trace for each edge in the graph and specify its color manually.
thanks for the suggestion @ghproek - we're unlikely to get to this any time soon, but I'd be happy to prioritize review of a community PR. thanks - @gvwilson
In fact I just discovered that this function already exists!
Input:
import plotly
colorscale = plotly.colors.get_colorscale('Bluered')
print(plotly.colors.sample_colorscale(colorscale, 0.5))
print(plotly.colors.sample_colorscale(colorscale, [0.1, 0.2]))
Output:
['rgb(128, 0, 128)']
['rgb(26, 0, 230)', 'rgb(51, 0, 204)']
I've used Plotly for years and years and never found this in the documentation. What would be really helpful is if this function were explicitly demoed in the main pages you hit when you search for color scales, e.g. https://plotly.com/python/builtin-colorscales. Would that be at all feasible?
cc @LiamConnors for documentation