扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
这篇文章主要讲解了“怎么用Python绘制柱形图”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么用Python绘制柱形图”吧!
成都创新互联公司是专业的麦盖提网站建设公司,麦盖提接单;提供网站设计制作、成都网站制作,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行麦盖提网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
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绘制柱形图这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流