pyecharts——Python数据可视化必备神器

快速入门 

#使用Jupyter Lab时必须在顶部声明Notebook类型
#from pyecharts.globals import CurretConfig,NotebookType
#CurretConfig.NOTEBOOK_TYPE = NotebookType.JUPYTER_LAB

from pyecharts.charts import Bar,Line
#使用 options 配置项,在 pyecharts 中,一切皆 Options
from pyecharts import options as opts
from pyecharts.render import make_snapshot
#snapshot-selenium渲染成图片
from snapshot_selenium import snapshot
# 内置主题类型pyecharts.globals.ThemeType
from pyecharts.globals import ThemeType

'''
Note: 在使用 Pandas&Numpy 时,
请确保将数值类型转换为 python 原生的 int/float。
比如整数类型请确保为 int,而不是 numpy.int32
'''
def first_bar():
    #生成bar对象,支持链式操作,render()生成html文件
    bar = (
        Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
        .add_xaxis(['广州塔','中山大学','长隆','动物园','植物园'])
        .add_yaxis('好评数',[1111,999,888,555,123])
        .add_yaxis('点评数',[1222,1009,1200,777,699])
        .set_global_opts(title_opts=opts.TitleOpts("广州"))
        ).render()

    #第一次加载js
    #bar.load_javascript()

    #渲染成图像文件
    make_snapshot(snapshot,bar,'广州.png')


if __name__ == '__main__':
    first_bar()

可视化结果:

发布了161 篇原创文章 · 获赞 90 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/qq_42415326/article/details/97272938