01折线图---pyecharts

Intro

可视化的整体要求为实现即可,无需关注细节,毕竟可视化只是手段。

import pyecharts
from pyecharts.charts import Line
from pyecharts import options as opts
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

[1] http://pyecharts.org/#/zh-cn/rectangular_charts?id=line%ef%bc%9a%e6%8a%98%e7%ba%bf%e9%9d%a2%e7%a7%af%e5%9b%be

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值