Python-玩转数据-大屏可视化利器Pyecharts

本文介绍了Python数据可视化库Pyecharts的使用,包括Grid、Overlap组件的组合应用,以及分页组件Tab和Page的示例。通过这些组件,可以灵活地创建和组合各种图表,实现数据的高效展示。
摘要由CSDN通过智能技术生成

一、说明

Echarts 是一个由百度开源的数据可视化,凭借着良好的交互性,精巧的图表设计,得到了众多开发者的认可。而 Python 是一门富有表达力的语言,很适合用于数据处理。当数据分析遇上数据可视化时,pyecharts 诞生了。

二、官方参考网址

pyecharts基本实用参考:
https://pyecharts.org/#/zh-cn/
pyecharts代码效果参考:
https://gallery.pyecharts.org/#/Bar/bar_with_brush

三、组合组件

1、Grid组件

首先介绍Pyecharts模块当中的Grid组件,使用Grid组件可以很好地将多张图无论是上下组合还是左右组合,都能够很好地拼接起来,我们先来看第一个例子
上下组合:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# time : 2022/2/25 0025

from pyecharts.charts import Bar,Line,Grid
from pyecharts import options as opt
import random

cate = ['1月', '2月', '3月', '4月', '5月', '6月','7月','8月','9月','10月','11月','12月']

bar = (
    Bar()
    .add_xaxis(cate)
    .add_yaxis('月订单数',[random.randint(100,200) for _ in cate])
    .add_yaxis('月订单完成数',[random.randint(50,100) for _ in cate])
    .set_global_opts(title_opts = opt.TitleOpts(title='直方图'))
)

bar.render('bar.html')

lines = (
    Line()
    .add_xaxis(cate)
    .add_yaxis('月订单数',[random.randint(100,200) for _ in cate])
    .add_yaxis('月订单完成数',[random.randint(50,100) for _ in cate])
    .set_global_opts(title_opts=opt.TitleOpts(title='折线图',pos_top='48%'),
                     legend_opts=opt.LegendOpts(pos_top = '48%'))
)

lines.render('lines.html')

grid = (
    Grid()
    .add(bar,
         grid_opts=opt.GridOpts(pos_bottom='60%'))
    .add(lines,grid_opts=opt.GridOpts(pos_top='50%'))
    .render('水平组合图.html')
)

在这里插入图片描述
左右组合:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#  time : 2022/2/25 0025

from pyecharts.charts import Bar,Line,Grid
from pyecharts import options as opt
import random

cate = ['1月', '2月', '3月', '4月', '5月', '6月','7月','8月','9月','10月','11月','12月']

bar = (
    Bar()
    .add_xaxis(cate)
    .add_yaxis('月订单数',[random.randint(100,200) for _ in cate])
    .add_yaxis('月订单完成数',[random.randint(50,100) for _ in cate])
    .set_global_opts(title_opts = opt.TitleOpts(title='直方图'),
                     legend_opts=opt.LegendOpts(pos_left='20%'))
)

bar.render('bar.html')

lines = (
    Line()
    .add_xaxis(cate)
    .add_yaxis('月订单数',[random.randint(100,200) for _ in cate])
    .add_yaxis('月订单完成数',[random.randint(50,100) for _ in cate])
    .set_global_opts(title_opts=opt.TitleOpts(title='折线图',pos_right='5%'),
                     legend_opts=opt.LegendOpts(pos_right='20%')
                     )
)

grid2 = (
    Grid()
    .add(bar, grid_opts=opt.GridOpts(pos_left="60%"))
    .add(lines, grid_opts=opt.GridOpts(pos_right="50%"))
    .render("垂直组合图.html")
)

在这里插入图片描述
可以看到我们无论是想上下拼接还是左右拼接,都可以通过调整参数“pos_left”、“pos_right”、“pos_top”以及“pos_bottom”这几个参数来实现。

地图和折线图拼接

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# time : 2022/2/25 0025

from pyecharts.charts import Bar,Line,Grid,Map
from pyecharts import options as opt
import random

cate = ['1月', '2月', '3月', '4月', '5月', '6月','7月','8月','9月','10月','11月','12月']
lines = (
    Line()
    .add_xaxis(cate)
    .add_yaxis('月订单数',[random.randint(100,200) for _ in cate])
    .add_yaxis('月订单完成数',[random.randint(50,100) for _ in cate])
    .set_global_opts(title_opts=opt.TitleO
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值