您好,登錄后才能下訂單哦!
這篇文章主要講解了“怎么用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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。