为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用 graph_objects 子模块在 plotly sunburst 图表上设置颜色?

如何使用 graph_objects 子模块在 plotly sunburst 图表上设置颜色?

陪伴而非守候 2023-06-20 15:18:23
如果我使用 plotly express 子模块,我可以通过以下方式创建彩色旭日图:import plotly.express as pxnames = ["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"]parents = ["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve" ]values = [10, 14, 12, 10, 2, 6, 6, 4, 4]color_discrete_sequence = ['#2D5F91', '#FFAA00', '#96BEE6', '#48B7B4', '#E8655F',                           '#819FBD', '#FFCC66', '#C0D8F0', '#91D4D2', '#F1A39F']fig = px.sunburst(    names=names,    parents=parents,    values=values,    color_discrete_sequence = color_discrete_sequence,)fig.show()我想对 plotly 的 graph_objects 做同样的事情。有没有类似的功能?
查看完整描述

1 回答

?
森栏

TA贡献1810条经验 获得超5个赞

该版本在官方参考graph_objects中可用。

import plotly.graph_objects as go


color_discrete_sequence = ['', '#FFAA00', '#2D5F91','#819FBD','#819FBD','#91D4D2', '#96BEE6', '#C0D8F0','#E8655F','#F1A39F','#48B7B4']


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=\[10, 14, 12, 10, 2, 6, 6, 4, 4\],

    marker=dict(colors=color_discrete_sequence)

))

# Update layout for tight margin

# See https://plotly.com/python/creating-and-updating-figures/

fig.update_layout(margin = dict(t=0, l=0, r=0, b=0))


fig.show()

//img2.sycdn.imooc.com/649152df0001c42305080389.jpg

查看完整回答
反对 回复 2023-06-20
  • 1 回答
  • 0 关注
  • 84 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信