宠物实例:
from pyecharts.charts import Pie # Pie 饼状图
from pyecharts import options
result=[["泰迪犬",20],["金毛犬",20],["哈士奇",45],["比熊犬",25],["萨摩耶",24]]
pie=(
Pie()
.add("宠物种类",result)
.set_global_opts(title_opts=options.TitleOpts(title="主标题",subtitle="副标题"))
# 全局配置项 标题配置项
.set_series_opts(label_opts=options.LabelOpts(formatter="{a}.{b} :{c} -- > {d}%"))
# 系列配置项
)
pie.render("宠物狗排行.html")
options.LabelOpts 标签配置项
options.TitleOpts
商品实例:
from pyecharts.charts import Bar
from pyecharts import options as opt
# print(type(Bar()))
bar=(
Bar().add_xaxis(["衬衫","裤子","围巾","袜子","毛衣"])
.add_yaxis("京东",[23,44,55,23,55])
.add_yaxis("淘宝", [33, 225, 44, 74, 60])
.add_yaxis("拼多多", [14, 58, 78, 69, 89])
.set_global_opts(title_opts=opt.TitleOpts(title="主标题",subtitle="副标题"))
)
bar.render("商品目录.html")
import requests
from pyecharts.charts import Map
from pyecharts import options as opt
from datetime import date
from pyecharts.globals import ThemeType
update_time=date.today()
url="https://www.tianqiapi.com/api?version=epidemic&appid=23035354&appsecret=8YvlPNrz"
respond=requests.get(url).json()
# print(respond)
list=[]
for i in respond['data']['area']:
# print(i)
# print(i["provinceShortName"],i["confirmedCount"])
list.append([i['provinceShortName'],i['confirmedCount']])
map=(
Map()
.add("全国疫情图",list,"china")
.set_global_opts(
title_opts=opt.TitleOpts(title="全国疫情图",subtitle="更新时间:{}".format(update_time)),
visualmap_opts=opt.VisualMapOpts(
is_show=True,
min_=0,
max_=1000
)
)
)
map.render("全国疫情.html")