python - 如何从 Python 中的字符串列表制作旭日形图?
问题描述
我有一个字符串列表:
How many glasses are on the tab ?
What does the sign say ?
Has the pizza been baked ?
Do you think the boy on the ground has broken legs ?
Is this man crying ?
How many pickles are on the plate ?
What is the shape of the plate?
…
如何将其转换为 Python 中的旭日形图?
旭日形图通过前四个单词显示问题的分布,弧长与包含该单词的问题数量成正比,白色区域是贡献太小而无法显示的单词。
(图片来源->第5页,图3)
问题 如何在 R 或 Python 中制作旭日形图?不对输入格式做出任何假设,Python 的答案假设输入的格式非常不同。
解决方案
扩展Jimmy Ata的答案,它指向 Python plotly 包:
您可以使用https://plotly.com/python/sunburst-charts/:
来自同一页面的示例:
# From https://plotly.com/python/sunburst-charts/
import plotly.express as px
data = dict(
character=["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
parent=["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve" ],
value=[10, 14, 12, 10, 2, 6, 6, 4, 4])
fig =px.sunburst(
data,
names='character',
parents='parent',
values='value',
)
fig.show()