pyecharts操作三
-
pyecharts 是一个用于生成Echarts图表的Python库。Echarts是百度开源的一个数据可视化JS库,可以生成一些非常酷炫的图表。
-
环境安装
- pip install pyecharts
-
检查版本
import pyecharts
print(pyecharts.version)
2.0.3
- GL关系图
import random
from pyecharts import options as opts
from pyecharts.charts import GraphGL
nodes = []
for i in range(50):
for j in range(50):
nodes.append(
opts.GraphGLNode(
x=random.random() * 958,
y=random.random() * 777,
value=1,
)
)
links = []
for i in range(50):
for j in range(50):
if i < 50 - 1:
links.append(
opts.GraphGLLink(
source=i + j * 50,
target=i + 1 + j * 50,
value=1,
)
)
if j < 50 - 1:
links.append(
opts.GraphGLLink(
source=i + j * 50,
target=i + (j + 1) * 50,
value=1,
)
)
gl = (
GraphGL(init_opts=opts.InitOpts())
.add(
series_name=“”,
nodes=nodes,
links=links,
itemstyle_opts=opts.ItemStyleOpts(color=“rgba(255,231,114,0.8)”),
linestyle_opts=opts.LineStyleOpts(color=“rgba(255,231,114,0.8)”, width=3),
force_atlas2_opts=opts.GraphGLForceAtlas2Opts(
steps=5,
edge_weight_influence=4,
),
)
.set_dark_mode()
)
gl.render_notebook()
- 图形组件
from pyecharts import options as opts
from pyecharts.charts import Bar
from pyecharts.commons.utils import JsCode
from pyecharts.faker import Faker
gr = (
Bar()
.add_xaxis(Faker.choose())
.add_yaxis(“商家A”, Faker.values())
.add_yaxis(“商家B”, Faker.values())
.set_global_opts(
title_opts=opts.TitleOpts(title=“图形组件示例”),
graphic_opts=[
opts.GraphicGroup(
graphic_item=opts.GraphicItem(
rotation=JsCode(“Math.PI / 4”),
bounding=“raw”,
right=110,
bottom=110,
z=100,
),
children=[
opts.GraphicRect(
graphic_item=opts.GraphicItem(
left=“center”, top=“center”, z=100
),
graphic_shape_opts=opts.GraphicShapeOpts(width=400, height=50),
graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
fill=“rgba(0,0,0,0.3)”
),
),
opts.GraphicText(
graphic_item=opts.GraphicItem(
left=“center”, top=“center”, z=100
),
graphic_textstyle_opts=opts.GraphicTextStyleOpts(