美文网首页python
pyecharts柱状图进阶篇

pyecharts柱状图进阶篇

作者: 践行数据分析 | 来源:发表于2020-10-22 17:36 被阅读0次

    双纵坐标柱状图

    如果想把温度和降雨量画在同一个柱状图内,一个纵坐标就不够用了

    import  pyecharts.options   as   opts

    from   pyecharts.charts   import   Bar, Line

    x_data = ["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"]

    bar = (

    Bar(init_opts=opts.InitOpts(width="1000px", height="600px"))

    .add_xaxis(xaxis_data=x_data)

    .add_yaxis(

    series_name="蒸发量",

    yaxis_index=0,

    yaxis_data=[2.0,4.9,7.0,23.2,25.6,76.7,135.6,162.2,32.6,20.0,6.4,3.3,],

    label_opts=opts.LabelOpts(is_show=False),

    )

    .add_yaxis(

    series_name="平均温度",

    yaxis_index=1,

    yaxis_data=[2.0,2.2,3.3,4.5,6.3,10.2,20.3,23.4,23.0,16.5,12.0,6.2],

    label_opts=opts.LabelOpts(is_show=False),

    )

    .extend_axis(

    yaxis=opts.AxisOpts(

    name="温度",

    type_="value",

    min_=0,

    max_=25,

    interval=5,

    axislabel_opts=opts.LabelOpts(formatter="{value} °C"),

    )

    )

    .set_global_opts(

    tooltip_opts=opts.TooltipOpts(

    is_show=True, trigger="axis", axis_pointer_type="cross"

    ),

    xaxis_opts=opts.AxisOpts(

    type_="category",

    axispointer_opts=opts.AxisPointerOpts(is_show=True, type_="shadow"),

    ),

    yaxis_opts=opts.AxisOpts(

    name="水量",

    type_="value",

    min_=0,

    max_=250,

    interval=50,

    axislabel_opts=opts.LabelOpts(formatter="{value} ml"),

    axistick_opts=opts.AxisTickOpts(is_show=True),

    splitline_opts=opts.SplitLineOpts(is_show=True),

    ),

    )

    )

    bar.render_notebook()

    extend_axis:增加了以温度为刻度的纵坐标轴

    add_yaxis:yaxis_index=0表示该数据用第一个坐标轴,yaxis_index=1表示该数据用第二个坐标轴



    为柱状图添加动画

    简单的出场方式已经不能满足我的需要了,我需要酷炫一点的

    from   pyecharts   import    options   as   opts

    from   pyecharts.charts    import   Bar

    from   pyecharts.faker   import   Faker

    l1=[100,200,300,400,500,400,300]

    l2=[300,400,500,400,300,200,100]

    bar = (

    Bar(

    init_opts=opts.InitOpts(

    animation_opts=opts.AnimationOpts(

    animation_delay=1000, animation_easing="bounceIn"

    )

    )

    )

    .add_xaxis(Faker.choose())

    .add_yaxis("商家A", l1)

    .add_yaxis("商家B", l2)

    .set_global_opts(title_opts=opts.TitleOpts(title="Bar-动画配置基本示例", subtitle="我是副标题"))

    )

    bar.render_notebook()

    animation_delay设置延迟时间

    animation_easing设置动画效果

    相关文章

      网友评论

        本文标题:pyecharts柱状图进阶篇

        本文链接:https://www.haomeiwen.com/subject/gtjuuktx.html