pyecharts 安装
pip安装
pip(3) install pyecharts
源码安装
$ git clone https://github.com/pyecharts/pyecharts.git
$ cd pyecharts
$ pip install -r requirements.txt
$ python setup.py install
# 或者执行 python install.py
查看版本
import pyecharts
print(pyecharts.__version__)
示例
from pyecharts.charts import Bar# 使用 options 配置项,在 pyecharts 中,一切皆 Options。
from pyecharts import options as opts# 内置主题类型可查看 pyecharts.globals.ThemeType
from pyecharts.globals import ThemeType# V1 版本开始支持链式调用
# 你所看到的格式其实是 `black` 格式化以后的效果
# 可以执行 `pip install black` 下载使用
bar = (Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT)).add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]).add_yaxis("商家A", [5, 20, 36, 10, 75, 90]).set_global_opts(title_opts=opts.TitleOpts(title="主标题", subtitle="副标题"))# 或者直接使用字典参数# .set_global_opts(title_opts={"text": "主标题", "subtext": "副标题"})
)
# render 会生成本地 HTML 文件,默认会在当前目录生成 render.html 文件
# 也可以传入路径参数,如 bar.render("mycharts.html")
# 也可以在jupyter使用render_notebook(),将直接打印
bar.render()# 不习惯链式调用的开发者依旧可以单独调用方法
bar = Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
bar.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"])
bar.add_yaxis("商家A", [5, 20, 36, 10, 75, 90])
bar.set_global_opts(title_opts=opts.TitleOpts(title="主标题", subtitle="副标题"))
bar.render()
Note: 在使用 Pandas&Numpy 时,请确保将数值类型转换为 python 原生的 int/float。比如整数类型请确保为 int,而不是 numpy.int32