pycharm——树状图

复制代码
from pyecharts import options as opts
from pyecharts.charts import Tree


data = [
    {
        "children": [
            {"name": "计算机"},
            {
                "children": [{"children": [{"name": "主机"}], "name": "硬盘"}, {"name": "鼠标和键盘"}],
                "name": "硬件",
            },
            {
                "children": [
                    {"children": [{"name": "操作系统"}, {"name": "数据结构"}], "name": "组成原理"},
                    {"name": "基础"},
                ],
                "name": "软件",
            },
        ],
        "name": "数学",
    }
]
c = (
    Tree()
    .add("", data)
    .set_global_opts(title_opts=opts.TitleOpts(title="Tree-基本示例"))
    .render("tree_base.html")
)
复制代码
import json

from pyecharts import options as opts
from pyecharts.charts import Tree

with open("flare.json", "r", encoding="utf-8") as f:
    j = json.load(f)
c = (
    Tree()
    .add("", [j], collapse_interval=2, layout="radial")
    .set_global_opts(title_opts=opts.TitleOpts(title="Tree-Layout"))
    .render("tree_layout.html")
)

flare.json文件

复制代码
 {
    "name": "My Library",
    "children": [
        {
            "name": "Book",
            "children": [
                {"name": "Title", "value": "The Great Gatsby"},
                {"name": "Author", "value": "F. Scott Fitzgerald"},
                {"name": "Publication Date", "value": "1925-04-10"}
            ]
        },
        {
            "name": "Library",
            "children": [
                {"name": "Name", "value": "Central Library"},
                {"name": "Location", "value": "New York"}
            ]
        },
        {
            "name": "Characters",
            "children": [
                {"name": "Jay Gatsby", "value": "Wealthy Gambler"},
                {"name": "Nick Carraway", "value": "Narrator"},
                {"name": "Daisy Buchanan", "value": "Socialite"}
            ]
        },
        {
          "name": "competer",
          "children": [
            {"name": "数据结构","value": "50"},
            {"name": "数据库原理","value": "60"},
            {"name": "计算机组成网络","value": "40"}
          ]
         }
    ]
}
相关推荐
程序员佳佳41 分钟前
文章标题:彻底抛弃OpenAI官方Key?实测GPT-5.2与Banana Pro(Gemini 3):这才是开发者的终极红利!
开发语言·人工智能·python·gpt·ai作画·api·midjourney
qq_356196951 小时前
day49_通道注意力机制 @浙大疏锦行
python
Yeats_Liao1 小时前
MindSpore开发之路(十四):简化训练循环:高阶API `mindspore.Model` 的妙用
人工智能·python·深度学习
写代码的【黑咖啡】1 小时前
Python中的Pandas:数据分析的利器
python·数据分析·pandas
机器懒得学习1 小时前
WGAN-GP RVE 生成系统深度技术分析
python·深度学习·计算机视觉
晨光32111 小时前
Day43 训练和测试的规范写法
python·深度学习·机器学习
海棠AI实验室1 小时前
Python 学习路线图:从 0 到 1 的最短闭环
开发语言·python·学习
玄同7651 小时前
Python 函数:LLM 通用逻辑的封装与复用
开发语言·人工智能·python·深度学习·语言模型·自然语言处理
俞凡1 小时前
深入理解 Python GIL
python
luoluoal2 小时前
基于python的自然语言处理技术的话题文本分类的研究(源码+文档)
python·mysql·django·毕业设计·源码