pyecharts介绍
pyecharts 是一个用于生成 Echarts 图表的类库。Echarts 是百度开源的一个数据可视化 JS 库。用 Echarts 生成的图可视化效果非常棒
为避免绘制缺漏,建议全部安装
为了避免下载缓慢,作者全部使用镜像源下载过了
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ echarts-countries-pypkg
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ echarts-china-provinces-pypkg
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ echarts-china-cities-pypkg
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ echarts-china-counties-pypkg
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ echarts-china-misc-pypkg
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ echarts-united-kingdom-pypkg
基础案例
from pyecharts.charts import Bar
bar = Bar()
bar.add_xaxis(['小嘉','小琪','大嘉琪','小嘉琪'])
bar.add_yaxis('得票数',[60,60,70,100])
#render会生成本地HTML文件,默认在当前目录生成render.html
# bar.render()
#可以传入路径参数,如 bar.render("mycharts.html")
#可以将图形在jupyter中输出,如 bar.render_notebook()
bar.render_notebook()
from pyecharts.charts import Bar
from pyecharts import options as opts
# 示例数据
cate = ['Apple', 'Huawei', 'Xiaomi', 'Oppo', 'Vivo', 'Meizu']
data1 = [123, 153, 89, 107, 98, 23]
data2 = [56, 77, 93, 68, 45, 67]
# 1.x版本支持链式调用
bar = (Bar()
.add_xaxis(cate)
.add_yaxis('渠道', data1)
.add_yaxis('门店', data2)
.set_global_opts(title_opts=opts.TitleOpts(title="示例", subtitle="副标"))
)
bar.render_notebook()
from pyecharts.charts import Pie
from pyecharts import options as opts