文章目录
- 一、绘制折线图
- 二、添加最小值最大值平均值
- 三、竖线提示信息
- 四、显示工具栏
- 五、实心面积填充
- 六、是否跳过空值
- 七、折线光滑化
- 八、多X轴
- 九、阶梯图
一、绘制折线图
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折线图](https://img.it610.com/image/info8/93c84e4291ed4d4a89f68b77549656f2.jpg)
文章图片
import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.faker import Fakerc = (
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折线图](https://img.it610.com/image/info8/d8aabcdfa95c4cb49ec8ed27b10c43fd.jpg)
文章图片
二、添加最小值最大值平均值
import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.faker import Fakerc = (
Line()
.add_xaxis(cnbodfgbsort.TYPE.tolist())
.add_yaxis("票价",cnbodfgbsort.PRICE.tolist())
.add_yaxis("人次",cnbodfgbsort.PERSONS.tolist(), markpoint_opts=opts.MarkPointOpts(
data=https://www.it610.com/article/[
opts.MarkPointItem(type_="max", name="最大值"),
opts.MarkPointItem(type_="min", name="最小值"),
]
),
markline_opts=opts.MarkLineOpts(
data=https://www.it610.com/article/[opts.MarkLineItem(type_="average", name="平均值")]
),)
.set_global_opts(title_opts=opts.TitleOpts(title="电影票价与人次"))
)
c.render_notebook()
![#|Python pyecharts Line折线图](https://img.it610.com/image/info8/2507e461dd1f4ba9bcbd20997bd364c9.jpg)
文章图片
![#|Python pyecharts Line折线图](https://img.it610.com/image/info8/a4168b040d2640a6a3b9767bcc91948e.jpg)
文章图片
三、竖线提示信息
tooltip_opts=opts.TooltipOpts(trigger="axis")
![#|Python pyecharts Line折线图](https://img.it610.com/image/info8/72e670b572b944e182b69a77f9dba43b.png)
文章图片
![#|Python pyecharts Line折线图](https://img.it610.com/image/info8/71586b08677347c58b8919c52aa53bd8.gif)
文章图片
四、显示工具栏
toolbox_opts=opts.ToolboxOpts(is_show=True)
![#|Python pyecharts Line折线图](https://img.it610.com/image/info8/2e1c1db5895144ab988e2d4957a072db.jpg)
文章图片
![#|Python pyecharts Line折线图](https://img.it610.com/image/info8/88de1e129fab41f5bd221ba5343d5beb.jpg)
文章图片
五、实心面积填充
.set_series_opts(
areastyle_opts=opts.AreaStyleOpts(opacity=0.5), # 透明度
label_opts=opts.LabelOpts(is_show=False), # 是否显示标签
)
![#|Python pyecharts Line折线图](https://img.it610.com/image/info8/5f4e635b7793493d85284195ab552b5d.jpg)
文章图片
六、是否跳过空值
import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.faker import Fakery = 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折线图](https://img.it610.com/image/info8/9ec7ad8607f94d83ae63a4d122ca60bc.jpg)
文章图片
![#|Python pyecharts Line折线图](https://img.it610.com/image/info8/7aaff43586f54d5da417082abb129a1d.jpg)
文章图片
# 使用这个参数来跳过空值,避免折现断掉
is_connect_nones=True
import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.faker import Fakery = 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折线图](https://img.it610.com/image/info8/6139ce59049b4eb499245ca827c625f9.jpg)
文章图片
七、折线光滑化
is_smooth=True
![#|Python pyecharts Line折线图](https://img.it610.com/image/info8/af0a1354cd0d481a8918237fd650bc73.jpg)
文章图片
![#|Python pyecharts Line折线图](https://img.it610.com/image/info8/949ed69c146d43d2b977dff122d082fa.jpg)
文章图片
八、多X轴 参考官网:》multiple_x_axes
![#|Python pyecharts Line折线图](https://img.it610.com/image/info8/88f3ba0e94c6464ebcf1e0346a348a3d.gif)
文章图片
九、阶梯图
is_step=True
【#|Python pyecharts Line折线图】
![#|Python pyecharts Line折线图](https://img.it610.com/image/info8/b01c3595b94346dd80f26680d6fd9664.jpg)
文章图片
![#|Python pyecharts Line折线图](https://img.it610.com/image/info8/d10394c9ce4d48e4b11837217a73b454.jpg)
文章图片
推荐阅读
- python|DRF 多对一反向查找 序列化
- Python|Python之单元测试使用的一点心得
- Notes|Python: 如何去除字符串多余的空格、换行符(二)
- 接口|python 调用web接口导入表格文件
- 爬虫|一个简单的网络爬虫-获取全国新型冠状肺炎疫情
- Python|用python爬取全国和全球疫情数据,并进行可视化分析(过程详细代码可运行)
- Python爬虫|每日一练(Python爬虫爬取全国新冠肺炎疫情数据实例详解,使用beautifulsoup4库实现)
- Python爬虫|python爬虫(网易新冠疫情数据爬取(一))
- Python日常小操作|Python爬取疫情数据