python - 如何更改 plot.ly 中旭日形图的颜色?
问题描述
我希望所有的哺乳动物都是黄色的,所有的爬行动物都是绿色的。我不能使用情节快递,因为我的学校不允许。代码如下:
import plotly.graph_objs as go
fig = go.Figure(go.Sunburst(
labels=["Animal", "Reptile", "Lizard", "Snake", "Bird", "Salamander",
"Canary", "tweetle", "Mammal", "Equine", "Bovine", "Canine",
"Horse", "Zebra", "Cow", "Lassle", "Rintintin", "Bessle"],
parents=["", "Animal", "Reptile", "Reptile", "Reptile", "Lizard",
"Bird", "Canary", "Animal", "Mammal", "Mammal", "Mammal",
"Equine", "Equine", "Bovine", "Canine", "Canine", "Cow"],
))
fig.update_layout(margin = dict(t=0, l=0, r=0, b=0))
fig.show()
解决方案
df
我认为如果你可以利用你的数据做一些逆向工程,我认为有更好的方法,px
你可以尝试
import plotly.graph_objs as go
labels = ["Animal", "Reptile", "Lizard", "Snake", "Bird", "Salamander",
"Canary", "tweetle", "Mammal", "Equine", "Bovine", "Canine",
"Horse", "Zebra", "Cow", "Lassle", "Rintintin", "Bessle"]
parents = ["", "Animal", "Reptile", "Reptile", "Reptile", "Lizard",
"Bird", "Canary", "Animal", "Mammal", "Mammal", "Mammal",
"Equine", "Equine", "Bovine", "Canine", "Canine", "Cow"]
colors = []
for p in labels:
if p in ["Reptile", "Lizard", "Snake", "Bird", "Salamander",
"Canary", "tweetle"]:
colors.append("green")
elif p in ["", "Animal"]:
colors.append("white")
else:
colors.append("yellow")
fig = go.Figure(
go.Sunburst(
labels=labels,
parents=parents,
marker=dict(colors=colors)
)
)
fig.update_layout(margin = dict(t=0, l=0, r=0, b=0))
fig.show()
推荐阅读
- f# - 查找实现接口的类,使用反射,并在 F# 中实例化它们
- neo4j - 计算路径中的不同节点
- python - 无法在pygame中移动捕手角色
- java - 将 XML 转换为 Markdown 格式文本
- javascript - React Native 在 Android 和 iOS 上获取 html 不同的结果
- ionic4 - 无法解析所有参数 Ioni
- verilog - 如何生成依赖于 systemverilog 中先前参数的参数
- python - 合并、汇总和重命名数据框中的行
- python - 在解析之前使用 lxml 注册命名空间
- sql - 获取具有更新值的新列,其中每一行随时间变化取决于实际列?