Pyecharts__1.x 版本 __Bar 简单实现

整体 

from pyecharts.charts import Bar #从 pyecharts 的 charts 库中导入 条形图
from pyecharts import options as opts

bar = (
    Bar()  # 实例化一个 Bar 类 的对象 并 设置其基本配置
    #配置类型有  x轴,y轴,系列参数(如label标签),全局参数(如标题,xy轴的配置,图例)
    .add_xaxis()
    .add_yaxis()
    .set_series_opts()
    .set_global_opts()
)
# 以html形式保存  或者 在 jupyter中显示
bar.render('Bar.html')
# bar.render_notebook()

常用简单设置 

.add_xaxis(['January','February','March','April','May']) #以列表形式添加数据
.add_yaxis('我是图例',[100,200,300,400,500])#Bar 必须要有个 图例 legend
.set_global_opts() 

#global 里面的常用简单配置项
title_opts=opts.TitleOpts(title='我是标题',subtitle='我是副标题')
yaxis_opts=opts.AxisOpts(name='Y轴名称',name_rotate=60,min_=-10,max_=1000,splitline_opts=opts.SplitLineOpts(is_show=True))
legend_opts=opts.LegendOpts()

.set_series_opts()
#series里面的常用参数
label_opts(color='blue',position='insidetop')


#legend 是图例   label是图上的标签

实例:

from pyecharts.charts import Bar #从 pyecharts 的 charts 库中导入 条形图
from pyecharts import options as opts

bar = (
    Bar()  
    .add_xaxis([1,2,3,4,5])
    .add_yaxis('legend',[6,7,8,9,10])
    .set_series_opts(label_opts=opts.LabelOpts(color='blue',position='insideTop'))
    .set_global_opts(title_opts=opts.TitleOpts(title='title',subtitle='subtitle'))
    .set_global_opts(yaxis_opts=opts.AxisOpts(name='name',name_rotate=60,min_=-10,max_=25,splitline_opts=opts.SplitLineOpts(is_show=True)))
    .set_global_opts(legend_opts=opts.LegendOpts())
)
 
bar.render_notebook()

bar=(
       Bar( )
       .add_xaxis(['January','February','March','April','May'])
       .add_yaxis('Sales',[100,200,300,400,500])
       .set_global_opts(yaxis_opts=opts.AxisOpts(name='Y轴名称'                                   
                                     ,name_rotate=60 #坐标轴名字旋转角度                                                 
                                     ,min_=0  #最小时候
                                     ,max_=20000 #最大值                                                 
                                     ,splitline_opts=opts.SplitLineOpts(is_show=True)                                                                                       
                                     )
       )
)


bar.render_notebook() 
bar = (
    Bar()
    .add_xaxis(['January','February','March','April','May'])
    .add_yaxis('Sales',[10,20,30,40,50])
    #.set_series_opts()
    .set_global_opts(title_opts=opts.TitleOpts(title='2020年1-5月销量',subtitle='subtitle'))
    .set_global_opts(legend_opts=opts.LegendOpts())
    .set_global_opts(yaxis_opts=opts.AxisOpts(name='Y轴名称'
                   ,name_rotate=60
                   ,min_=-10
                   ,max_=100
                   ,splitline_opts=opts.SplitLineOpts(is_show=True)
                                             )
                    )
    .set_series_opts(label_opts=opts.LabelOpts(color='blue'
                                              ,position='insideTop' #设置数据标签所在的位置 'top','left','right','bottom','inside','insideLeft','insideRight'
                                                            # 'insideTop','insideBottom', 'insideTopLeft','insideBottomLeft'
                                                            # 'insideTopRight','insideBottomRight'
                                              ))   
#     .set_series_opts(label_opts=opts.LabelOpts(color='',opsition=''))
)  
                     
bar.render_notebook()

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值