python pychart 图片_“Matplotlib与Python数据可视化的pyecharts”朝阳图,之,Pyecharts,旭日...

11.6.2

绘制我的家庭树旭日图

为了分析我的家庭的人员相互关系,绘制了我的家庭树旭日图,Python代码如下:

# -*- coding: utf-8 -*-

#

声明

Notebook

类型,必须在引入

pyecharts.charts

等模块前声明

from pyecharts.globals import CurrentConfig, NotebookType

CurrentConfig.NOTEBOOK_TYPE = NotebookType.JUPYTER_LAB

from pyecharts import options as opts

from pyecharts.charts import Sunburst

def sunburst() -> Sunburst:

data = [

opts.SunburstItem(

name="

爷爷

",

children=[

opts.SunburstItem(

name="

李叔叔

",

value=15,

children=[

opts.SunburstItem(name="

表妹李诗诗

", value=2),

opts.SunburstItem(

name="

表哥李政

",

value=5,

children=[opts.SunburstItem(name="

表侄李佳

", value=2)],

),

opts.SunburstItem(name="

表姐李诗

", value=4),

],

),

opts.SunburstItem(

name="

爸爸

",

value=10,

children=[

opts.SunburstItem(name="

", value=5),

opts.SunburstItem(name="

哥哥李海

", value=1),

],

),

],

),

opts.SunburstItem(

name="

三爷爷

",

children=[

opts.SunburstItem(

name="

李叔叔

",

children=[

opts.SunburstItem(name="

表哥李靖

", value=1),

opts.SunburstItem(name="

表妹李静

", value=2),

],

)

],

),

]

c = (

Sunburst()

.add(series_name="

我的家庭树旭日图

", data_pair=data, radius=[0, "90%"])

.set_global_opts(title_opts=opts.TitleOpts(title="

我的家庭树旭日图

"),

toolbox_opts=opts.ToolboxOpts())

.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}"))

)

return c

#

第一次渲染时候调用

load_javasrcript

文件

sunburst().load_javascript()

#

展示数据可视化图表

sunburst().render_notebook()

在Jupyter lab中运行上述代码,生成如图11-6所示的旭日图。

图11-6  旭日图

你可能感兴趣的:(python,pychart,图片)