11-pyecharts使用Tab不完全代码示例
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")
作者:lotuslaw
出处:https://www.cnblogs.com/lotuslaw/p/15200750.html
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
2020-08-28 N皇后问题