这篇文章主要讲解了“怎么用Python绘制柱形图”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么用Python绘制柱形图”吧!
bar = ( Bar() .add_xaxis(x_vals) .add_yaxis("广州门店", [random.randint(10, 100) for _ in range(6)]) .add_yaxis("中山门店", [random.randint(10, 100) for _ in range(6)]) .add_yaxis("深圳门店", [random.randint(10, 100) for _ in range(6)]) .add_yaxis("东莞门店", [random.randint(10, 100) for _ in range(6)]) .set_series_opts(label_opts=opts.LabelOpts(is_show=True, font_size=14), markline_opts=opts.MarkLineOpts(data=[opts.MarkLineItem(y=40, name="达标线=40")])) .set_global_opts(title_opts=opts.TitleOpts(title='实际销售金额', subtitle="QDM"), xaxis_opts=opts.AxisOpts(name='商品'), yaxis_opts=opts.AxisOpts(name='单位:万元')) ) # bar.render('柱状图.html') # 或者 bar.render_notebook()
渲染效果:
goods = ["蔬菜","水果","猪肉","电商","综合","水产"] bar = ( Bar() .add_xaxis(goods) .add_yaxis('供应商A', [random.randint(10, 100) for _ in range(6)], stack='stack1') .add_yaxis('供应商B', [random.randint(10, 100) for _ in range(6)], stack='stack1') .add_yaxis('供应商C', [random.randint(10, 100) for _ in range(6)], stack='stack1') .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title="实际销售数量"), xaxis_opts=opts.AxisOpts(name="品类"), yaxis_opts=opts.AxisOpts(name="销量(单位:件)")) ) # bar.render('柱状堆叠图.html') # 或者 bar.render_notebook()
渲染效果:
# 条形图 x_vals1 = ["白鲳鱼","小生蚝","秋刀鱼","多春鱼","南鲳鱼","海三宝"] x_vals2 = ["银鱼仔","基围虾","沙甲","多宝鱼","泥猛","鲍鱼"] x_vals3 = ["中鲫鱼","武昌鱼","白花鱼","海鲈鱼","眉草鱼","大乌头"] # 把模拟的随机数改为列表形式,并按升序排列 y_vals = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18] bar = Bar().add_xaxis(x_vals1 + x_vals2 + x_vals3) bar.add_yaxis("品控打折验收单品", y_vals, markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_='average'), opts.MarkPointItem(type_='max'), opts.MarkPointItem(type_='min')], symbol_size=80) ) bar.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position="right")) # 条目较多条形图比较好看点 bar.set_global_opts(title_opts=opts.TitleOpts(title="打折单品个数", subtitle="邮件")) bar.reversal_axis() #翻转XY轴,将柱状图转换为条形图 # bar.render('条形图.html') # 或者 bar.render_notebook()
渲染效果:
# 条形图 # 把3个列表合并为一个列表----> 需要用到Excel中的 Ctrl+H , Windows+10 , ",">
渲染效果:
# 条形图(纯净版) # 把3个列表合并为一个列表----> 需要用到Excel中的 Ctrl+H , Windows+10 , "," 快捷键 x_vals1 = ["白鲳鱼","小生蚝","秋刀鱼","多春鱼","南鲳鱼","海三宝","银鱼仔","基围虾","沙甲","多宝鱼","泥猛","鲍鱼", "中鲫鱼","武昌鱼","白花鱼","海鲈鱼","眉草鱼","大乌头"] # 把模拟的随机数改为列表形式,并按升序排列 y_vals = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18] bar = Bar().add_xaxis(x_vals1) bar.add_yaxis("品控打折验收单品", y_vals, ) bar.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position="right")) # 条目较多条形图比较好看点 bar.set_global_opts(title_opts=opts.TitleOpts(title="打折单品个数", subtitle="邮件")) bar.reversal_axis() #翻转XY轴,将柱状图转换为条形图 # bar.render('条形图.html') # 或者 bar.render_notebook()
渲染效果:
感谢各位的阅读,以上就是“怎么用Python绘制柱形图”的内容了,经过本文的学习后,相信大家对怎么用Python绘制柱形图这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。