如何绘制树形图

2023-12-29 16:23:07
from pyecharts import options as opts
from pyecharts.charts import Tree

# 定义树形结构
tree_data = [
   {
       "name": "A",
       "children": [
           {"name": "B", "children": [{"name": "E"}, {"name": "F"}]},
           {"name": "C", "children": [{"name": "G"}, {"name": "H"}]},
       ],
   },
   {"name": "D", "children": [{"name": "I"}, {"name": "J"}]},
]

# 创建树形图
tree = Tree()
tree.add("", tree_data)

# 设置树形图配置项
tree.set_global_opts(title_opts=opts.TitleOpts(title="树形图"))

# 渲染树形图
tree.render("tree.html")

请添加图片描述

文章来源:https://blog.csdn.net/qq_38412868/article/details/135291557
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。