本文是为了帮助大家快速掌握十大顶级绘图方法,重点解释数据是如何呈现在不同类型图中。
使用pip install pyecharts
安装,安装后的版本为 v1.6
pyecharts
几行代码就能绘制出有特色的的图形,绘图API链式调用,使用方便。
1 仪表盘
from pyecharts import charts
# 仪表盘
gauge = charts.Gauge()
gauge.add('Python小例子', [('Python机器学习', 30), ('Python基础', 70.),
('Python正则', 90)])
gauge.render(path="./data/仪表盘.html")
print('ok')
仪表盘中共展示三项,每项的比例为30%,70%,90%,如下图默认名称显示第一项:Python机器学习
,完成比例为30%
2 漏斗图
from pyecharts import options as opts
from pyecharts.charts import Funnel, Page
from random import randint
def funnel_base() -> Funnel:
c = (
Funnel()
.add("豪车", [list(z) for z in zip(['宝马', '法拉利', '奔驰', '奥迪', '大众', '丰田', '特斯拉'],
[randint(1, 20) for _ in range(7)])])
.set_global_opts(title_opts=opts.TitleOpts(title="豪车漏斗图"))
)
return c
funnel_base().render('./img/car_funnel.html')
print('ok')
以7种车型及某个属性值绘制的漏斗图,属性值大越靠近漏斗的大端。
3 日历图
import datetime
import random
from pyecharts import options as opts
from pyecharts.charts import Calendar
def calendar_interval_1() -> Calendar:
begin = datetime.date(2019, 1, 1)