数据可视化pyecharts学习笔记---折线图

直角坐标系图表–折线图

from pyecharts.charts import Line

1、基本示例

from pyecharts import options as opts
from pyecharts.charts import Line
from pyecharts.faker import Faker

line = Line()
line.add_xaxis(Faker.choose())
line.add_yaxis("商家A",Faker.values())
line.set_global_opts(title_opts=opts.TitleOpts(title="折线图基本示例"))
line.render("./html/line_base.html")

数据可视化pyecharts学习笔记---折线图_第1张图片

2、连接空数据

is_connect_nones=True

from pyecharts import options as opts
from pyecharts.charts import Line
from pyecharts.faker import Faker

y = Faker.values()
y[1] = None
y[3] = None
line = Line()
line.add_xaxis(Faker.choose())
line.add_yaxis("商家A",y,is_connect_nones=True)
line.set_global_opts(title_opts=opts.TitleOpts(title="Line-连接空数据"))
line.render("./html/line_connect_none.html")

数据可视化pyecharts学习笔记---折线图_第2张图片

3、平滑曲线

is_smooth=True

from pyecharts import options as opts
from pyecharts.charts import Line
from pyecharts.faker import Faker

line = Line()
line.add_xaxis(Faker.choose())
line.add_yaxis("商家A",Faker.values(),is_smooth=True)
line.add_yaxis("商家B",Faker.values(),is_smooth=True)
line.set_global_opts(title_opts=opts.TitleOpts(title="曲线图"))
line.render("./html/line_smooth.html")

数据可视化pyecharts学习笔记---折线图_第3张图片

4、线条和图元样式

linestyle_opts
itemstyle_opts

from pyecharts import options as opts
from pyecharts.charts import Line
from pyecharts.faker import Faker

line = Line()
line.add_xaxis(Faker.choose())
line.add_yaxis("商家A",Faker.values(),
               symbol="triangle",   # 标记图形为三角形
               symbol_size=20)      # 标记图形大小
line.set_global_opts(title_opts=opts.TitleOpts(title="线条和图元样式"))
line.set_series_opts(
    linestyle_opts=opts.LineStyleOpts(   # 线样式配置项
        color="green",   # 线的颜色
        width=4,         # 线宽(默认为1)
        type_="dashed"),# 线的类型
    itemstyle_opts=opts.ItemStyleOpts(   # 图元样式配置项
        color="blue",        # 图形颜色
        border_width=3,      # 边界宽度
        border_color="yellow"# 边界颜色
    )
)
line.render("./html/line_style.html")

数据可视化pyecharts学习笔记---折线图_第4张图片

5、双X轴

from pyecharts import options as opts
from pyecharts.charts import Line

line = Line(init_opts=opts.InitOpts(width="1600px",height="800px"))
line.add_xaxis(xaxis_data=["2019-1", "2019-2", "2019-3", "2019-4", "2019-5", "2019-6",
                           "2019-7", "2019-8", "2019-9", "2019-10", "2019-11", "2019-12"])
line.extend_axis(xaxis_data=["2018-1", "2018-2", "2018-3", "2018-4", "2018-5", "2018-6",
                           "2018-7", "2018-8", "2018-9", "2018-10", "2018-11", "2018-12"],
                xaxis=opts.AxisOpts(axispointer_opts=opts.AxisPointerOpts(is_show=True))  # 坐标轴指示器
                )
line.add_yaxis("2018 降水量",[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3],
               is_smooth=True,  # 平滑曲线
               is_symbol_show=False   # 不显示标记图形
               )
line.add_yaxis("2019 降水量",[3.9, 5.9, 11.1, 18.7, 48.3, 69.2, 231.6, 46.6, 55.4, 18.4, 10.3, 0.7],
               is_smooth=True,
               is_symbol_show=False
               )
line.set_global_opts(
    tooltip_opts=opts.TooltipOpts(trigger="none",axis_pointer_type="cross"),# 提示框触发类型以及指示器类型
    xaxis_opts=opts.AxisOpts(axispointer_opts=opts.AxisPointerOpts(is_show=True)),  # 坐标轴指示器
    yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True))  # 显示标记线
)
line.set_series_opts(
    linestyle_opts=opts.LineStyleOpts(width=4),
    label_opts=opts.LabelOpts(is_show=False)
)
line.render("./html/line_multi_xaxis.html")

数据可视化pyecharts学习笔记---折线图_第5张图片

6、堆叠折线图

from pyecharts import options as opts
from pyecharts.charts import Line
from pyecharts.faker import Faker

line = Line()
line.add_xaxis(Faker.choose())
line.add_yaxis("商家A",Faker.values(),stack="0")
line.add_yaxis("商家B",Faker.values(),stack="0")
line.add_yaxis("商家C",Faker.values(),stack="0")
line.set_global_opts(title_opts=opts.TitleOpts(title="堆叠折线图"),
                     tooltip_opts=opts.TooltipOpts(trigger="axis"),  # 坐标轴触发
                     xaxis_opts=opts.AxisOpts(boundary_gap=False),   # 默认True类目轴中刻度作为分隔
                     yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)))   # 显示分割线
line.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
line.render("./html/line_stack.html")

数据可视化pyecharts学习笔记---折线图_第6张图片

7、堆叠面积图

areastyle_opts

from pyecharts import options as opts
from pyecharts.charts import Line
from pyecharts.faker import Faker

line = Line()
line.add_xaxis(Faker.choose())
line.add_yaxis("商家A",Faker.values(),stack="0")
line.add_yaxis("商家B",Faker.values(),stack="0")
line.add_yaxis("商家C",Faker.values(),stack="0")
line.set_global_opts(title_opts=opts.TitleOpts(title="面积堆叠图"),
                     tooltip_opts=opts.TooltipOpts(trigger="axis"),  # 坐标轴触发
                     xaxis_opts=opts.AxisOpts(boundary_gap=False),   # 默认True类目轴中刻度作为分隔
                     yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)))   # 显示分割线
line.set_series_opts(label_opts=opts.LabelOpts(is_show=False),
                     areastyle_opts=opts.AreaStyleOpts(opacity=0.5))
line.render("./html/line_area_stack.html")

数据可视化pyecharts学习笔记---折线图_第7张图片

你可能感兴趣的:(数据可视化pyecharts)