zoukankan      html  css  js  c++  java
  • 20200903(pyecharts进阶-1)

    以下代码均在jupyter notebook 中运行。

    一、全局配置

    参照:https://pyecharts.org/#/zh-cn/global_options,所需功能可在该网站查找,参照下面代码格式举一反三实现所需。

    from pyecharts import options as opts
    from pyecharts.charts import Bar
    from pyecharts.faker import Faker
    
    x = ["哈士奇", "泰迪", "金毛", "柯基", "吉娃娃", "牧羊犬"]
    y1 = [140, 136, 144, 120, 119, 150]
    y2 = [130, 146, 24, 110, 79, 110]
    
    bar = Bar()
    bar.add_xaxis(x)
    bar.add_yaxis("商家A", y1)
    bar.add_yaxis("商家B", y2)
    #bar.reversal_axis()  #横向
    #全局配置:标题,坐标轴,图例
    bar.set_global_opts(title_opts=opts.TitleOpts(title="宠物狗的销售价格", subtitle="两个商家的对比", 
                                                  title_link = "https://www.baidu.com",
                                                 pos_left = 'center'), 
                        xaxis_opts=opts.AxisOpts( name_rotate = 90),
                       datazoom_opts = opts.DataZoomOpts(is_show = True),
                       legend_opts = opts.LegendOpts(pos_left = "right"))
    
    
    bar.render_notebook()

    图:

     二、系列配置项

    • set_series_opts
    from pyecharts import options as opts
    from pyecharts.charts import Bar
    from pyecharts.faker import Faker
    
    x = ["哈士奇", "泰迪", "金毛", "柯基", "吉娃娃", "牧羊犬"]
    y1 = [140, 136, 144, 120, 119, 150]
    y2 = [130, 146, 24, 110, 79, 110]
    
    bar = Bar()
    bar.add_xaxis(x)
    bar.add_yaxis("商家A", y1)
    bar.add_yaxis("商家B", y2)
    
    #全局配置:标题,坐标轴,图例
    bar.set_global_opts(title_opts=opts.TitleOpts(title="宠物狗的销售价格", subtitle="两个商家的对比", 
                                                  title_link = "https://www.baidu.com",
                                                 pos_left = 'center'), 
                        xaxis_opts=opts.AxisOpts( name_rotate = 90),
                       datazoom_opts = opts.DataZoomOpts(is_show = True),
                       legend_opts = opts.LegendOpts(pos_left = "right"))
    #系列配置项;
    bar.set_series_opts(label_opts = opts.LabelOpts(is_show = False),
                       markpoint_opts = opts.MarkPointOpts(
                           data = [
                               opts.MarkPointItem(type_ = "max", name = "最大值"),
                               opts.MarkPointItem(type_ = "min", name = "最小值"),  #
                       ]))
    
    bar.render_notebook()

     三、除了上面两种方式之外,还可以直接放在x 轴或者y 轴上进行修饰

    from pyecharts import options as opts
    from pyecharts.charts import Bar
    from pyecharts.faker import Faker
    
    x = ["哈士奇", "泰迪", "金毛", "柯基", "吉娃娃", "牧羊犬"]
    y1 = [140, 136, 144, 120, 119, 150]
    y2 = [130, 146, 24, 110, 79, 110]
    
    bar = Bar()
    bar.add_xaxis(x)
    bar.add_yaxis("商家A", y1,itemstyle_opts = opts.ItemStyleOpts(color = "blue"))
    bar.add_yaxis("商家B", y2)
    
    #全局配置:标题,坐标轴,图例
    bar.set_global_opts(title_opts=opts.TitleOpts(title="宠物狗的销售价格", subtitle="两个商家的对比", 
                                                  title_link = "https://www.baidu.com",
                                                 pos_left = 'center'), 
                        xaxis_opts=opts.AxisOpts( name_rotate = 90),
                       datazoom_opts = opts.DataZoomOpts(is_show = True),
                       legend_opts = opts.LegendOpts(pos_left = "right"))
    #系列配置项;
    bar.set_series_opts(label_opts = opts.LabelOpts(is_show = False),
                       markpoint_opts = opts.MarkPointOpts(
                           data = [
                               opts.MarkPointItem(type_ = "max", name = "最大值"),
                               opts.MarkPointItem(type_ = "min", name = "最小值"),  #
                       ]))
    
    bar.render_notebook()

     四、我们再来看一些其他的具体示例

    1.主题(全局,InitOpts)

    pyecharts内置提供了10+种不同的风格,另外也提供了便捷的定制主题的方法

    from pyecharts import options as opts
    from pyecharts.charts import Bar
    from pyecharts.globals import ThemeType
    
    x = ["哈士奇", "泰迪", "金毛", "柯基", "吉娃娃", "牧羊犬"]
    y1 = [140, 136, 144, 120, 119, 150]
    y2 = [130, 146, 24, 110, 79, 110]
    
    bar = Bar(init_opts = opts.InitOpts(theme=ThemeType.WALDEN))
    bar.add_xaxis(x)
    bar.add_yaxis("商家A", y1)
    bar.add_yaxis("商家B", y2)
    
    #全局配置:标题,坐标轴,图例
    bar.set_global_opts(title_opts=opts.TitleOpts(title="宠物狗的销售价格", subtitle="两个商家的对比", 
                                                  title_link = "https://www.baidu.com",
                                                 pos_left = 'center'), 
                        xaxis_opts=opts.AxisOpts( name_rotate = 90),
                       datazoom_opts = opts.DataZoomOpts(is_show = True),
                       legend_opts = opts.LegendOpts(pos_left = "right"))
    #系列配置项;
    bar.set_series_opts(label_opts = opts.LabelOpts(is_show = False),
                       markpoint_opts = opts.MarkPointOpts(
                           data = [
                               opts.MarkPointItem(type_ = "max", name = "最大值"),
                               opts.MarkPointItem(type_ = "min", name = "最小值"),  #
                       ]))
    
    bar.render_notebook()

  • 相关阅读:
    HDU 2023题解分析
    Java中常见的几种类型转换
    Software Version --hdu1976
    单词数
    Usaco 2.3 Zero Sums(回溯DFS)--暴搜
    9的余数
    mongodb学习(一)
    svg学习(九)path
    svg学习(八)polyline
    qunit学习(一)
  • 原文地址:https://www.cnblogs.com/bltstop/p/13608541.html
Copyright © 2011-2022 走看看