叠加多图
graph1.render_notebook()
choose = Faker.choose()
values = Faker.values()
graph1 = (Line()
.add_xaxis(choose)
.add_yaxis("",values)
)
graph2 = (Bar()
.add_xaxis(choose)
.add_yaxis("",values)
)
graph1.overlap(graph2)
graph1.render_notebook()
并行多图
choose = Faker.choose()
values = Faker.values()
graph1 = (Line()
.add_xaxis(choose)
.add_yaxis("", values)
)
graph2 = (Bar()
.add_xaxis(choose)
.add_yaxis("", values)
)
grid = (Grid()
.add(graph1, grid_opts=opts.GridOpts(pos_left="55%", pos_right="5%"))
.add(graph2, grid_opts=opts.GridOpts(pos_left="5%", pos_right="50%"))
)
grid.render_notebook()
顺序多图
choose = Faker.choose()
values = Faker.values()
graph1 = (Line()
.add_xaxis(choose)
.add_yaxis("", values)
)
graph2 = (Bar()
.add_xaxis(choose)
.add_yaxis("", values)
)
page = Page()
page.add(graph1)
page.add(graph2)
page.render_notebook()
选项卡多图
name = list("选项卡多图")
tab = Tab()
for i in name:
graph = (Line()
.add_xaxis(Faker.choose())
.add_yaxis("",Faker.values())
)
tab.add(graph, i)
tab.render_notebook()
时间轮播多图
timeline = Timeline()
for i in range(1, 31):
graph = (Line()
.add_xaxis(Faker.choose())
.add_yaxis("", Faker.values())
)
timeline.add(graph, "2022-11-{}".format(i))
timeline.render_notebook()
系列配置项
from pyecharts import options as opts
文字样式配置项
graph1 = (Line(init_opts=opts.InitOpts(width = "500px", height="500px"))#配置初始化项
.add_xaxis(Faker.choose())
.add_yaxis("test", Faker.values())
.set_global_opts(
title_opts = opts.TitleOpts(title="我是主标题",
title_textstyle_opts = opts.TextStyleOpts(color = "red",
font_style = "oblique",
font_weight = "lighter",
font_size=50,
font_family="Arial")),
legend_opts = opts.LegendOpts(is_show = True, pos_left = "70%",
#图例字体样式调整
textstyle_opts = opts.TextStyleOpts(color="green",
font_style = "oblique",
font_weight="lighter",
font_size=50,
font_family="Arial"))
)
)
graph1.render_notebook()
标签配置项
graph1 = (Line(init_opts=opts.InitOpts(width='800px', height='500px'))
.add_xaxis(Faker.choose())
.add_yaxis("text", Faker.values())
.set_series_opts(label_opts=opts.LabelOpts(is_show=True,
position='insideTopleft',
rotate=0)
)
)
graph1.render_notebook()
标记点配置项
graph1 = (Bar(init_opts=opts.InitOpts(width='800px', height='500px'))
.add_xaxis(Faker.choose())
.add_yaxis("手机品牌",Faker.values())
.set_series_opts(label_opts=opts.LabelOpts(is_show=False),
markpoint_opts=opts.MarkPointOpts(
data=[opts.MarkPointItem(type_="max", name="最大值",
itemstyle_opts=opts.ItemStyleOpts(color="green"))],
label_opts=opts.LabelOpts(position="outside")
))
)
graph1.render_notebook()
标记线配置顶
graph1 = (Bar(init_opts=opts.InitOpts(width='800px', height='500px'))
.add_xaxis(Faker.choose())
.add_yaxis("手机品牌",Faker.values())
.set_series_opts(label_opts=opts.LabelOpts(is_show=False),
markline_opts=opts.MarkLineOpts(
data=[opts.MarkLineItem(type_="min", name="最小值")],
linestyle_opts = opts.LineStyleOpts(width=5, color = "black", type_='dotted'),
label_opts=opts.LabelOpts(color='black', is_show=True,rotate=30)
)
)
)
graph1.render_notebook()
标记区域配置项
choose = Faker.choose()
values = Faker.values()
graph1 = (Line(init_opts=opts.InitOpts(width='800px', height='500px'))
.add_xaxis(choose)
.add_yaxis("lyh",values)
.set_series_opts(
markarea_opts=opts.MarkAreaOpts(
data=[opts.MarkAreaItem(name="部分数据", x=('华为','魅族'))],
itemstyle_opts=opts.ItemStyleOpts(color="green",
border_color='black',
opacity=0.5),
label_opts=opts.LabelOpts(color='black', is_show=True, rotate=0))
)
)
graph1.render_notebook()
初始化配置项
graph1 = (
Line(
init_opts=opts.InitOpts(
#关闭图像动画
animation_opts=opts.AnimationOpts(animation=False),
#设置画布宽度
width='600px',
#设置高度
height='400px',
#设置画布背景颜色
bg_color='rgba(68, 130, 180, 0.1)',
#设置主题
theme='roma',
#设置网页名称
page_title='test'
)
)
.add_xaxis(choose)
.add_yaxis("", values)
)
graph1.render_notebook()
标题配置项
graph1 = (Bar()
.add_xaxis(choose)
.add_yaxis("", values)
.set_global_opts(
title_opts=opts.TitleOpts(
# 主标题内容
title = '我是主标题',
#副标题内容
subtitle='我是副标题',
# 主标题链接
title_link='https://www.baidu.com',
# 标题位置
pos_left='right',
#pos_top="5%",
#主副标题的间距
item_gap=10,
#字体设置
title_textstyle_opts=opts.TextStyleOpts(color='red', font_size=30)
)))
graph1.render_notebook()
图元配置
graph1 =(Bar(init_opts=opts.InitOpts(width='500px', height='500px'))
.add_xaxis(choose)
.add_yaxis("A", values)
.add_yaxis("B", Faker.values(),
itemstyle_opts=opts.ItemStyleOpts(
color='green',
border_color='blank',
opacity=0.5,
border_width=3
))
)
graph1.render_notebook()
线条配置项
line = (Line(init_opts=opts.InitOpts(width='500px', height='500px'))
.add_xaxis(choose)
.add_yaxis('solid', Faker.values(), linestyle_opts = opts.LineStyleOpts(type_="solid"))
.add_yaxis('dashed', Faker.values(), linestyle_opts = opts.LineStyleOpts(type_="dashed"))
.add_yaxis('dotted', Faker.values(), linestyle_opts = opts.LineStyleOpts(type_="dotted",
width=5,
color='blue'))
)
line.render_notebook()
渲染生成出图片
from pyecharts.render import make_snapshot
from snapshot_selenium import snapshot
graph1 = (Line()
.add_xaxis(Faker.choose())
.add_yaxis("", Faker.values())
)
make_snapshot(snapshot, graph1.render(),"line.png")
安装snapshot_selenium,实现Pyecharts渲染图片 首先打开anaconda prompt
- pip install snapshot_selenium -i https://pypi.tuna.tsinghua.edu.cn/simple
- 找到anaconda的安装路径:C:\ProgramData\Anaconda3 将chromedriver.exe放在里面 (查看浏览器对应的版本去下载:
下载地址:http://chromedriver.storage.googleapis.com/index.html)- 计算机—>属性—>高级系统设置–> 系统变量—>Path—>添加路径:C:\ProgramData\Anaconda3\chromedriver.exe