一、说明
pyecharts模块,在引用前需要先安装,可通过pip安装; 输入命令:pip install pyecharts
from pyecharts.faker import Faker
二、模块介绍
通过查看Faker源码了解Faker中的函数介绍,其中具体如下所示:
部分说明: print(Faker.clothes) 结果为:[‘衬衫’, ‘毛衣’, ‘领带’, ‘裤子’, ‘风衣’, ‘高跟鞋’, ‘袜子’] print(Faker.drinks) 结果为:[‘可乐’, ‘雪碧’, ‘橙汁’, ‘绿茶’, ‘奶茶’, ‘百威’, ‘青岛’]
Faker.values()函数介绍 查看源码可知,取7个整数,在20-150范围随机抽取
部分说明: print(Faker.values()) 结果为:[81, 49, 95, 75, 146, 144, 43]
Faker.choose()函数介绍 查看源码可知,从clothes、drinks等随机返回
部分说明: print(Faker.choose()) 结果为:[‘衬衫’, ‘毛衣’, ‘领带’, ‘裤子’, ‘风衣’, ‘高跟鞋’, ‘袜子’]
三、应用
1、示例1
代码:
from pyecharts import options as opts
from pyecharts.charts import Pie
from pyecharts.faker import Faker
pie = (
Pie()
.add("", [list(z) for z in zip(Faker.choose(), Faker.values())])
.set_colors(["blue", "green", "yellow", "red", "pink", "orange", "purple"])
.set_global_opts(title_opts=opts.TitleOpts(title="颜色设置"))
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
)
pie.render()
结果:
2、示例2
代码:
import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.faker import Faker
c = (
Line()
.add_xaxis(Faker.choose())
.add_yaxis("storeA", Faker.values(), is_smooth=True)
.add_yaxis("storeB", Faker.values(), is_smooth=True)
.set_global_opts(title_opts=opts.TitleOpts(title="数据"))
)
c.render()
结果:
|