作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望所有的哺乳动物都是黄色的,所有爬行动物都是绿色的。我不能使用 plot express,因为我的学校不允许。代码如下:
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()
关于python - 如何在 plot.ly 中更改旭日图的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62578171/
我是一名优秀的程序员,十分优秀!