脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|shell|

服务器之家 - 脚本之家 - Python - Python pyecharts Line折线图的具体实现

Python pyecharts Line折线图的具体实现

2023-02-21 12:20温欣' Python

折线图在很多图标中都有使用,本文主要介绍了Python pyecharts Line折线图的具体实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

一、绘制折线图

import seaborn as sns
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams['font.sans-serif']=['Microsoft YaHei'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False # 用来正常显示负号
from datetime import datetime
plt.figure(figsize=(16,10))
import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.faker import Faker
from pyecharts.charts import Bar
import os
from pyecharts.options.global_options import ThemeType
# 读入数据
cnbodfgbsort=pd.read_csv("cnbodfgbsort.csv")

得到的cnbodfgbsort数据:

Python pyecharts Line折线图的具体实现

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

c = (
  Line()
  .add_xaxis(cnbodfgbsort.TYPE.tolist()) #X轴
  .add_yaxis("票价",cnbodfgbsort.PRICE.tolist()) #Y轴
  .add_yaxis("人次",cnbodfgbsort.PERSONS.tolist()) #Y轴
  .set_global_opts(title_opts=opts.TitleOpts(title="电影票价与人次")) #标题
)
c.render_notebook() # 显示

Python pyecharts Line折线图的具体实现

 

二、添加最小值最大值平均值

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

c = (
  Line()
  .add_xaxis(cnbodfgbsort.TYPE.tolist())
  .add_yaxis("票价",cnbodfgbsort.PRICE.tolist())
  .add_yaxis("人次",cnbodfgbsort.PERSONS.tolist(), markpoint_opts=opts.MarkPointOpts(
          data=[
              opts.MarkPointItem(type_="max", name="最大值"),
              opts.MarkPointItem(type_="min", name="最小值"),
          ]
      ),
      markline_opts=opts.MarkLineOpts(
          data=[opts.MarkLineItem(type_="average", name="平均值")]
      ),)
  .set_global_opts(title_opts=opts.TitleOpts(title="电影票价与人次"))
)
c.render_notebook()

Python pyecharts Line折线图的具体实现

Python pyecharts Line折线图的具体实现

 

三、竖线提示信息

tooltip_opts=opts.TooltipOpts(trigger="axis")

Python pyecharts Line折线图的具体实现

Python pyecharts Line折线图的具体实现

 

四、显示工具栏

tooltip_opts=opts.TooltipOpts(trigger="axis")

Python pyecharts Line折线图的具体实现

Python pyecharts Line折线图的具体实现

 

五、实心面积填充

.set_series_opts(
   areastyle_opts=opts.AreaStyleOpts(opacity=0.5), # 透明度
   label_opts=opts.LabelOpts(is_show=False), # 是否显示标签
)

Python pyecharts Line折线图的具体实现

 

六、是否跳过空值

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

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

如下图:y[3],y[5]数据都是空值,如果直接显示的话,图表会出错

Python pyecharts Line折线图的具体实现

Python pyecharts Line折线图的具体实现

# 使用这个参数来跳过空值,避免折现断掉
is_connect_nones=True
import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.faker import Faker

y = Faker.values()
y[3], y[5] = None, None
c = (
  Line()
  .add_xaxis(Faker.choose())
  .add_yaxis("商家A", y, is_connect_nones=True)
  .set_global_opts(title_opts=opts.TitleOpts(title="Line-连接空数据"))
)
c.render_notebook()

​

Python pyecharts Line折线图的具体实现

 

七、折线光滑化

is_smooth=True

Python pyecharts Line折线图的具体实现

Python pyecharts Line折线图的具体实现

 

八、多X轴

参考官网:》multiple_x_axes

Python pyecharts Line折线图的具体实现

 

九、阶梯图

is_step=True

Python pyecharts Line折线图的具体实现

Python pyecharts Line折线图的具体实现

到此这篇关于Python pyecharts Line折线图的具体实现的文章就介绍到这了,更多相关Python pyecharts Line折线图内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/wxfighting/article/details/123899778

延伸 · 阅读

精彩推荐