如何使用 plotly.graph_objects 控制 Sunburst 的颜色输入?
How to control the color input of a Sunburst with plotly.graph_objects?
我想控制下面旭日图中每个标签的颜色 - 当使用 plotly.graph_objects 而不是 [=25 时=].
请参阅下面 documentation 中的示例:
import plotly.graph_objects as go
fig =go.Figure(go.Sunburst(
labels=[ "Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
parents=["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve" ],
values=[ 65, 14, 12, 10, 2, 6, 6, 4, 4],
branchvalues="total",
))
fig.update_layout(margin = dict(t=0, l=0, r=0, b=0))
fig.show()
这将允许访问和控制标记:
import plotly.express as px
greys = px.colors.sequential.Greys
reds = px.colors.sequential.Reds
blues = px.colors.sequential.Blues
greens = px.colors.sequential.Greens
magents = px.colors.sequential.Magenta
fig.data[0].marker.colors = ['', greys[5], reds[5], reds[6], reds[7],
blues[5], greens[5], greens[6], magents[5]]
fig.show()
我想控制下面旭日图中每个标签的颜色 - 当使用 plotly.graph_objects 而不是 [=25 时=].
请参阅下面 documentation 中的示例:
import plotly.graph_objects as go
fig =go.Figure(go.Sunburst(
labels=[ "Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
parents=["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve" ],
values=[ 65, 14, 12, 10, 2, 6, 6, 4, 4],
branchvalues="total",
))
fig.update_layout(margin = dict(t=0, l=0, r=0, b=0))
fig.show()
这将允许访问和控制标记:
import plotly.express as px
greys = px.colors.sequential.Greys
reds = px.colors.sequential.Reds
blues = px.colors.sequential.Blues
greens = px.colors.sequential.Greens
magents = px.colors.sequential.Magenta
fig.data[0].marker.colors = ['', greys[5], reds[5], reds[6], reds[7],
blues[5], greens[5], greens[6], magents[5]]
fig.show()