Hi,
I encountered a problem while using plotly.colors. I would be thankful if you explain me why this happened (or point me to any document).
The following code outputs a list of ‘rgb(three float numbers)’.
import plotly.colors as pc
pc.n_colors(pc.sequential.Viridis[0], pc.sequential.Viridis[1], 10, colortype='rgb')
For example, the first element of the list is ‘rgb(68.0, 1.0, 84.0)’, which is the same as pc.sequential.Viridis[0] if we ignore the decimal part. Nonetheless if I plot a polygon by
import plotly.graph_objects as go
import plotly.colors as pc
# Figure settings
xlim = [0, 16]
ylim = [0, 3]
clim = [0, 1]
if __name__ == '__main__':
fig = go.Figure()
fig.add_trace(
go.Scatter(
x=[0, 1, 1, 0],
y=[0, 0, 1, 0],
mode='none',
fill='toself',
fillcolor='rgb(68.0, 1.0, 84.0)'
)
)
# Dummy trace to show a colorbar.
dummy_trace = go.Scatter(
x=xlim, y=ylim, mode='markers',
marker=dict(
size=0.1, color=clim, colorscale=pc.sequential.Viridis,
colorbar=dict(thickness=10), showscale=True),
hoverinfo='none'
)
fig.add_trace(dummy_trace)
fig.update_layout(showlegend=False)
fig.show()
the color of the polygon is different from ‘rgb(68, 1, 84)’. So, it seems that ‘rgb(68, 1, 84)’ and ‘rgb(68.0, 1.0, 84.0)’ are interpreted differently, but plotly.colors.n_colors is ignorant of this.
Am I missing something or using n_colors wrongly?
Thank you in advance!
Best regards,
Tadashi