折线图可以用来展现数据的趋势,大致写法如下:
from pyecharts.charts import Line,EffectScatterfrom pyecharts import options as optsx=["一月", "二月", "三月", "四月", "五月", "六月", "七月"]y=[114, 55, 27, 101, 125, 27, 105]line = ( Line() .add_xaxis(x) .add_yaxis('',y) .set_global_opts(title_opts=opts.TitleOpts(title="某情况"),toolbox_opts=opts.ToolboxOpts()))line.render()
生成的图如下:
这图现在很粗糙,我们稍微美化一下,我们更换一下风格,并配合涟漪图,生成的图片如下:代码如下:
from pyecharts.charts import Line,EffectScatterfrom pyecharts import options as optsfrom pyecharts.globals import ThemeTypex=["一月", "二月", "三月", "四月", "五月", "六月", "七月"]y=[114, 55, 27, 101, 125, 27, 105]es=EffectScatter()es.add_xaxis(x)es.add_yaxis('',y,symbol_size=12,symbol='circle')es.set_series_opts(label_opts=opts.LabelOpts(is_show=False))line = ( Line(init_opts=opts.InitOpts(theme=ThemeType.DARK)) .add_xaxis(x) .add_yaxis('',y) .overlap(es) .set_global_opts(title_opts=opts.TitleOpts(title="某情况"),toolbox_opts=opts.ToolboxOpts()))line.render()
注意下第11行,没有这一行,涟漪图的标签和折线图的标签会一同显示,标签指的是折线上的114,55,27这些数字。折线图和涟漪图用的是两种写法,涟漪图用的是单独调用,折线图用的是链式调用pyecharts还可以做出更美观的图,这就需要大家自己去学习