'color discrete sequence in a plotly graph objects [duplicate]
how can i plot a pie chart with color sequence while using plotly.graph_objects instead of plotly.express. In plotly.express is it very easy to do with the property "color_discrete_sequence". Is there something similar? Thank you
Solution 1:[1]
You could use the colors
attribute of the marker if I understand your problem correctly. Just get the color Sequence you want.
import plotly.graph_objects as go
import plotly.express as px
colors = px.colors.sequential.RdBu
fig = go.Figure(data=[go.Pie(labels=['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen'],
values=[4500,2500,1053,500])])
fig.update_traces(hoverinfo='label+percent', textinfo='value', textfont_size=20,
marker=dict(colors=colors, line=dict(color='#000000', width=2)))
fig.show()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |