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