首页 > 其他 > 详细

11-pyecharts使用Tab不完全代码示例

时间:2021-08-30 06:15:51      阅读:14      评论:0      收藏:0      [点我收藏+]
from pyecharts import options as opts
from pyecharts.charts import Bar, Grid, Line, Pie, Tab, Page, Scatter, Map
from pyecharts.components import Table
import matplotlib.pyplot as plt
from pyecharts.options import ComponentTitleOpts


def origin_data() -> Table:
    global res
    table = Table()
    headers = list(res.columns)
    rows = [list(res.iloc[index]) for index in res.index]
    table.add(headers, rows)
    table.set_global_opts(
        title_opts=ComponentTitleOpts(title="Top100")
    )
    return table


def distribute_cons_sex() -> Bar:
    global res
    c = (
    Bar(init_opts=opts.InitOpts(width="1300px"))
    .add_xaxis(b_cons_new)
    .add_yaxis("Top100_male", [round(cons/len(res[res[‘sex‘]==1]), 2) for cons in a_cons_male])
    .add_yaxis("Top100_female", [round(cons/len(res[res[‘sex‘]==2]), 2) for cons in a_cons_female])
    .set_global_opts(
        yaxis_opts=opts.AxisOpts(name="人数占比"),
        xaxis_opts=opts.AxisOpts(name="消费区间(单位:元)", axislabel_opts=opts.LabelOpts(rotate=-25)),
        title_opts=opts.TitleOpts(title="Top100-男女消费分布对比", pos_top=480),
        legend_opts=opts.LegendOpts(pos_top=530),
    )
    .set_series_opts(
        label_opts=opts.LabelOpts(is_show=False),
        markpoint_opts=opts.MarkPointOpts(
            data=[
                opts.MarkPointItem(type_="max", name="最大值")
            ]
        ),
    )
)
    return c


tab = Tab()
tab.add(origin_data(), "原始数据")
tab.add(grid_consumption, ‘消费分布‘)
tab.add(grid_sex, ‘性别分布‘)
tab.add(grid_age, ‘年龄分布‘)
tab.add(grid_height, ‘身高分布‘)
tab.add(grid_weight, ‘体重分布‘)
tab.add(grid_occupation, ‘职业分布‘)
tab.add(distribute_city(), ‘地域分布‘)
tab.render("消费前100用户属性分布.html")

11-pyecharts使用Tab不完全代码示例

原文:https://www.cnblogs.com/lotuslaw/p/15200750.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!