Intro
可视化的整体要求为实现即可,无需关注细节,毕竟可视化只是手段。
import pyecharts
from pyecharts.charts import Line
from pyecharts import options as
pyecharts.__version__
'1.6.2'
pyecharts版本1.6.2
x = list(range(0, 10))
y1 = [i * 2 + 1 for i in list(range(0, 10))]
y2 = [i * 3 + 2 for i in list(range(0, 10))]
y3 = [(i+1)/10 * 3 for i in list(range(0, 10))]
普通折线图
line1 = (
Line()
.add_xaxis(xaxis_data=x)
.add_yaxis("y1", y1
,color="blue",is_symbol_show=True
,label_opts=opts.LabelOpts(is_show=False)
,markline_opts=opts.MarkLineOpts(data=[opts.MarkLineItem(y=5)])# 设置水平线
)
.add_yaxis("y2", y2
,color="red",is_symbol_show=True
,label_opts=opts.LabelOpts(is_show=False)
,symbol="triangle"#设置点的形状'circle', 'rect', 'roundRect', 'triangle', 'diamond', 'pin', 'arrow', 'none'"rect"
,markline_opts=opts.MarkLineOpts(data=[opts.MarkLineItem(y=5)])
)
.set_colors(colors=["blue","red"]) # 如果不加上这句,legends和line的颜色不一致,这个相当于全局颜色设置
.set_global_opts(title_opts=opts.TitleOpts(title="Love",pos_right="50%") # 设置标题
,legend_opts=opts.LegendOpts(pos_right="10%",pos_top="20%",orient="vertical") # 设置图例
,tooltip_opts =opts.TooltipOpts(trigger='axis',axis_pointer_type='cross')
,toolbox_opts =opts.ToolboxOpts(is_show=True,orient='horizontal')
,xaxis_opts =opts.AxisOpts(name="Date")
,yaxis_opts =opts.AxisOpts(name="Rate")
)
)
line1.render_notebook()
双坐标轴折线图
line = (
Line()
.add_xaxis(x)
.add_yaxis("y1", y1
,color="blue",is_symbol_show=True
,label_opts=opts.LabelOpts(is_show=False)
)
.extend_axis(yaxis=opts.AxisOpts( name="y3"))
.set_global_opts(title_opts=opts.TitleOpts(title="双坐标轴Demo",pos_right="50%") # 设置标题
,legend_opts=opts.LegendOpts(pos_right="10%",pos_top="50%",orient="vertical") # 设置图例
,tooltip_opts =opts.TooltipOpts(trigger='axis',axis_pointer_type='cross')
,toolbox_opts =opts.ToolboxOpts(is_show=True,orient='horizontal')
,xaxis_opts =opts.AxisOpts(name="X")
,yaxis_opts =opts.AxisOpts(name="Y")
)
)
line1 = (Line()
.add_xaxis(x)
.add_yaxis("y3", y3
,color="red",is_symbol_show=True
,label_opts=opts.LabelOpts(is_show=False)
, yaxis_index=1))
line.overlap(line1)
line.render_notebook()
Ref