I made a color palette, with colors correlated to temperature (measured in Kelvin). The code to convert temperature to rgb I found here: https://gist.github.com/petrklus/b1f427accdf7438606a6
- Show the color palette
- Capture [r,g,b] in colorList
step_size = 10
colorList=[]
# from 0 K to 15 K, convert K to rgb, plot and capture
for i in range(0, 15000, step_size):
color = list(map(lambda div: div, convert_K_to_RGB(i)))
colorList.append(color)
plt.plot((i, i), (0, 1), linewidth=step_size/2.0, linestyle="-", color=color)
How to use this palette instead of a standard one in Plotly?
What I tried:
- Make a dict
dC = {'pallete':colorList}
- Make a pandas dataframe
dCpd = pd.DataFrame(dC)
- Extract RGB from pandas column
xRed = [dCpd['pallete'][i][0] for i in range(len(dCpd['pallete']))]
xGreen = [dCpd['pallete'][i][1] for i in range(len(dCpd['pallete']))]
xBlue = [dCpd['pallete'][i][2] for i in range(len(dCpd['pallete']))]
- Make a final dic to pass to plotly
xRGB = {'Red':xRed, 'Green':xGreen, 'Blue':xBlue}
- Plotly scatter 3D
fig = px.scatter_3d(datap,x = x, y = y, z = z, color=datap['B-V'],
color_continuous_scale= xRGB,
color_continuous_midpoint=0)
fig.show()
datap, is the pandas df I am trying to apply the color palette to. I am plotting the position of stars, and I want their color to represent the temperature. The logic is:
star B-V color index column (datap[B-V]) -> compute Temperature-> compute RGB from Temperature-> apply that color
The error I get:
Invalid value of type 'builtins.dict' received for the 'colorscale' property of make_figure
plot example with a standard color palette in plotly that works, but doesn't represent color-temperature correlation I am trying to implement:
fig = px.scatter_3d(datap,x = x, y = y, z = z, color=datap['B-V'],
color_continuous_scale=px.colors.diverging.Spectral_r,
color_continuous_midpoint= 0,
hover_data=(['Name','magV']))
fig.show()
I want the B-V color palette to be as the example in the first png


