折线图
from pyecharts.charts import Line
from pyecharts import options as opts
from pyecharts.faker import Faker
from pyecharts.globals import ThemeType
from pyecharts.globals import CurrentConfig,NotebookType
CurrentConfig.NOTEBOOK_TYPE = NotebookType.JUPYTER_LAB
c=(
Line()
.add_xaxis(Faker.choose())
.add_yaxis('商家A',Faker.values()) # 折线
.add_yaxis('商家B',Faker.values(),is_smooth=True) # 平滑
.set_global_opts(
title_opts=opts.TitleOpts(title='折线图'),
tooltip_opts=opts.TooltipOpts(trigger='axis') # 图像移动的时候有条竖线
)
)
c.render_notebook()
细节描绘 折线图
c=(
Line(
init_opts=opts.InitOpts(
width='800px',
height='500px'
)
)
.add_xaxis(xaxis_data=Faker.week)
.add_yaxis(
'商家A',
y_axis=[120,200,150,250,42,551,421],
symbol='triangle',
symbol_size=20,
# 线条样式
linestyle_opts=opts.LineStyleOpts(
color='green',
width=2,
type_='dashed'# 虚线
),
# 标签
label_opts=opts.LabelOpts(is_show=False),
# 点的属性
itemstyle_opts=opts.ItemStyleOpts(
border_width=2,
border_color='yellow',
color='blue',
),
# 标注点
markpoint_opts=opts.MarkPointOpts(
data=[
opts.MarkPointItem(type_='max'),
opts.MarkPointItem(type_='min'),
]
),
markline_opts=opts.MarkLineOpts(
data=[
opts.MarkLineItem(type_='average'), # 平均线
]
)
) # 折线
.set_global_opts(
yaxis_opts=opts.AxisOpts(
type_='value', #
splitarea_opts=opts.SplitLineOpts(is_show=True) # 分割线 平行于x轴的
),
tooltip_opts=opts.TooltipOpts(trigger='axis') # 图像移动的时候有条竖线
)
)
c.render_notebook()
面积图
x_data=['周一','周二','周三','周四','周五','周六','周日']
y_data=[820,932,901,934,1290,1330,1320]
c = (
Line()
.add_xaxis(xaxis_data=x_data)
.add_yaxis(
'',
y_axis=y_data,
areastyle_opts=opts.AreaStyleOpts(opacity=0.8))
.set_global_opts(
title_opts=opts.TitleOpts(title='面积图'),
tooltip_opts=opts.TooltipOpts(trigger='axis'),
# boundary_gap 和 y轴没有间隙
xaxis_opts=opts.AxisOpts(type_='category',boundary_gap=False)
)
)
c.render_notebook()
堆叠面积图
c = (
Line()
.add_xaxis(xaxis_data=x_data)
.add_yaxis(
'广告',
stack='堆叠',
y_axis=[120,40,60,50,45,65,84],
areastyle_opts=opts.AreaStyleOpts(opacity=0.8),
label_opts=opts.LabelOpts(is_show=False)
)
.add_yaxis(
'销售',
stack='堆叠',
y_axis=[120,40,60,50,45,65,84],
areastyle_opts=opts.AreaStyleOpts(opacity=0.8),
label_opts=opts.LabelOpts(is_show=False)
)
.add_yaxis(
'浏览',
stack='堆叠',
y_axis=[120,40,60,50,45,65,84],
areastyle_opts=opts.AreaStyleOpts(opacity=0.8),
label_opts=opts.LabelOpts(is_show=False)
)
.set_global_opts(
title_opts=opts.TitleOpts(title='堆叠面积图'),
tooltip_opts=opts.TooltipOpts(trigger='axis'),
# boundary_gap 和 y轴没有间隙
xaxis_opts=opts.AxisOpts(type_='category',boundary_gap=False)
)
)
c.render_notebook()
标签:PyEcharts,yaxis,--,add,xaxis,折线图,data,opts,axis
From: https://blog.csdn.net/HG0724/article/details/143487771