折线图
from pyecharts.globals import CurrentConfig, OnlineHostType
CurrentConfig.ONLINE_HOST = OnlineHostType.NOTEBOOK_HOST
import pandas as pd
import numpy as np
data = pd.DataFrame(np.random.randint(80,150,(20,3)), columns=['A','B','C'], index=pd.period_range('2020/03/15',periods=20,freq='D'))
data.head()
A B C
2020-03-15 87 143 112
2020-03-16 125 90 136
2020-03-17 137 98 119
2020-03-18 96 98 82
2020-03-19 135 148 89
from pyecharts.charts import Line
from pyecharts import options as opts
x = data.index.strftime('%m-%d').tolist()
data.iloc[5,0]=np.nan
带空值
line = Line(init_opts=opts.InitOpts(width='850px', height='350px'))
line.add_xaxis(x)
line.add_yaxis('', data['A'].tolist())
line.render_notebook()
基本设置-连接空值-轴的标签位置(点的位置)
在x轴的值以1开始时,尽管设置了boundary_gap=False,也无法对齐,此时可以将X轴的值变为str型
# 日期在刻度线中间,数据也在中间显示,空值断开
line = Line(init_opts=opts.InitOpts(width='850px', height='350px'))
line.add_xaxis(x)
line.add_yaxis('A', data['A'].tolist(),
is_connect_nones=True,# 连接空值
is_symbol_show=True, # 默认显示
symbol='pin', # 标记形状
symbol_size=10,
is_smooth=False, #是否平滑曲线
color='#33CCCC', # 系列颜色
linestyle_opts=opts.LineStyleOpts(width=2,type_='solid')
)
line.add_yaxis('B', data['B'].tolist(),color='#d14a61',
linestyle_opts=opts.LineStyleOpts(width=2,type_='dashed')
)
line.set_global_opts(
xaxis_opts=opts.AxisOpts(
boundary_gap=False, # x轴标签对应一点
axistick_opts=opts.AxisTickOpts(is_align_with_label=True) # 刻度线对齐标签
),
yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),
datazoom_opts=opts.DataZoomOpts(),
toolbox_opts=opts.ToolboxOpts(is_show=True),
tooltip_opts=opts.TooltipOpts(is_show=True, trigger='axis',axis_pointer_type='shadow')
)
line.render_notebook()
面积图-堆积
data.iloc[5,0]=100
line = Line(init_opts=opts.InitOpts(width='850px', height='350px'))
line.add_xaxis(x)
line.add_yaxis('A', data['A'].tolist(),is_smooth=True, color='#33CCCC',
stack='总量',
areastyle_opts=opts.AreaStyleOpts(opacity=0.7))
line.add_yaxis('B', data['B'].tolist(),is_smooth=True,color='#d14a