pip install pyecharts
即可,非常的简单方便。
pyecharts官方文档:通过官方文档,我们可以更加方便的学习其中各个图的绘制,官方文档中提供实例演示,非常的Nice。
from pyecharts import options as opts
from pyecharts.charts import Bar
bar = Bar()
# 一个列表
# x 轴的数据
bar.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"])
# 系列名称 系列数据
bar.add_yaxis("商家A",[5,20,36,10,75,90])
bar.set_global_opts(title=opts.TitleOpts(title='主标题',subtitle='副标题'))
bar.render_notebook()
# 链式调用
def bar_reveseral_axis() ->Bar:
# 类似类的实例化 返回值是一个Bar的实例对象
c = (
Bar()
.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"])
.add_yaxis("商家A",[5,20,36,10,75,90])
# 反转x y
.reversal_axis()
# 设置标签的位置 就是现实的值的位置
.set_series_opts(label_opts=opts.LabelOpts(opsition="right"))
.set_global_opts(title_opts=opts.TitleOpts(title="主标题",subtitle="副标题"))
)
return c
# 先实例化
bar_s = bar_revsersal_axis()
# bar_s.render_notebook()
bar_s.render('翻转柱状图.html')
from pyecharts.charts import Line
line = Line()
x = ['2018-{:0>2d}'.format(s) for s in range(1,13)]
y1 = [5,10,26,30,35,30,20,26,40,46,40,50]
y2 = [8,20,24,36,40,36,40,45,50,53,48,58]
line.add_xaxis(x)
line.add_yaxis('商家1',y1)
line.add_yaxis('商家2',y2)
line.render_notebook()
from pyecharts import options as opts
from pyecharts.charts import Scatter
from pyecharts.faker import Faker
scatter = Scatter()
scatter.add_xaxis(Faker.choose())
scatter.add_yaxis("商家A", Faker.values())
scatter.set_global_opts(
# 配置标题
title_opts=opts.TitleOpts(title="散点图(size)"),
# 配置视觉映射配置项 size 就是会根据数值大小改变点的大小
visualmap_opts=opts.VisualMapOpts(type_='size',max_=150,min_=20)
)
scatter.render_notebook()
上述也可用在地图中,下面演示:
from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.globals import ChartType
import numpy as np
geo = Geo()
areas = ['广东','广西','湖南','江西','福建']
values = [np.random.randint(1,1000) for x in range(5)]
geo.add_schema(maptype="china")
geo.add(
series_name="geo",
data_pair=[list(z) for z in zip(areas,values)],
type_='scatter',
symbol_size=12,
)
geo.set_global_opts(
title_opts=opts.TitleOpts(title="Geo"),
visualmap_opts=opts.VisualMapOpts(type_="size",max_=1000, min_=50)
)
geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
geo.render_notebook()
from pyecharts.charts import WordCloud
wd = WordCloud()
words = ['python','jupyter','numpy','pandas','matplotlib','sklearn',
'xgboost','lightGBM','simpy','keras','tensorflow',
'hive','hadoop','spark']
counts = [100,90,65,95,50,60,70,70,20,70,80,80,60,60]
wd.add(series_name="词云图",
data_pair=zip(words,counts),shape='triangle')
wd.render_notebook()
Pyecharts修炼之路(2)