可視化:pandas與pyecharts、堆疊圖、Stack_bar_percent


官網地址:https://gallery.pyecharts.org/#/Bar/stack_bar_percent

bar=Bar(init_opts = opts.InitOpts(height='350px'))

for label in pm_a["分段"].unique():
    p = pm_a[pm_a["分段"]==label]
    bar.add_xaxis(list(p["City1"]))
    bar.add_yaxis(label,list((p["比率"]*100).round(2)),stack="stack1") 

bar.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
bar.set_global_opts(
                    title_opts=opts.TitleOpts(title="各地市分布圖",pos_left="center"),
                   legend_opts=opts.LegendOpts(pos_top="8%"),
                   yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter="{value} %"),max_=100),
                    tooltip_opts=opts.TooltipOpts(formatter="{a}:{c} %")
                    )
bar.render_notebook()

說明:

1.for label in pm_a["分段"].unique():

針對各地市的四種負荷情況,label的值:低負荷、中等負荷、高負荷、超高負荷。

2. bar.add_xaxis(list(p["City1"]))

x軸方向針對地市。

3.bar.add_yaxis(label,list((p["比率"]*100).round(2)),stack="stack1") 

各種負荷中每個地市的比率,stack

4.

tooltip_opts=opts.TooltipOpts(formatter="{a}:{c} %")

# 標簽內容格式器,支持字符串模板和回調函數兩種形式,字符串模板與回調函數返回的字符串均支持用 \n 換行。
# 字符串模板 模板變量有:
# {a}:系列名。
# {b}:數據名。
# {c}:數據值。
# {@xxx}:數據中名為 'xxx' 的維度的值,如 {@product} 表示名為 'product'` 的維度的值。
# {@[n]}:數據中維度 n 的值,如{@[3]}` 表示維度 3 的值,從 0 開始計數。
# 示例:formatter: '{b}: {@score}'

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM