You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

多类别停车场总车位与占用车位可视化方案咨询

停车场占用数据可视化方案(Plotly实现及替代思路)

Treemap方案的可行性与实现

你的思路完全可行,Treemap能清晰呈现zone→lot的层级关系,同时通过颜色映射车位占用率、矩形大小对应总车位数(total),直观展示各区域的车位规模与使用效率。

Plotly Express实现代码:

import pandas as pd
import plotly.express as px

# 构造数据集
data = pd.DataFrame({
    "zone": ["A", "A", "B", "B"],
    "lot": ["A1", "A2", "B1", "B2"],
    "occupied": [80, 25, 15, 25],
    "total": [100, 50, 50, 25]
})

# 计算占用率百分比
data["occupancy_rate"] = (data["occupied"] / data["total"]) * 100

# 生成Treemap
fig = px.treemap(
    data,
    path=["zone", "lot"],  # 定义层级:zone为父节点,lot为子节点
    values="total",  # 矩形大小对应总车位数
    color="occupancy_rate",  # 颜色映射占用率
    color_continuous_scale="RdYlGn",  # 红-黄-绿配色,高占用率偏红
    hover_data={"occupied": True, "total": True, "occupancy_rate": ":,.1f%"}  # 悬停显示详情
)

fig.update_layout(margin=dict(t=50, l=25, r=25, b=25))
fig.show()

替代可视化方案

1. 分组堆叠条形图

适合对比每个lot的占用/空余车位绝对数量,按zone分组展示:

# 计算空余车位
data["available"] = data["total"] - data["occupied"]

fig = px.bar(
    data,
    x="lot",
    y=["occupied", "available"],
    color_discrete_map={"occupied": "#ff6b6b", "available": "#4ecdc4"},
    barmode="stack",
    facet_col="zone",
    labels={"value": "车位数量", "variable": "状态"},
    title="各区域车位占用/空余分布"
)
fig.show()

2. 旭日图(Sunburst)

与Treemap层级逻辑一致,但采用环形布局,更突出层级占比关系:

fig = px.sunburst(
    data,
    path=["zone", "lot"],
    values="total",
    color="occupancy_rate",
    color_continuous_scale="RdYlGn",
    hover_data={"occupied": True, "total": True}
)
fig.show()

3. 百分比条形图

专注展示各lot的占用比例,忽略总车位规模,适合对比不同区域的使用效率:

fig = px.bar(
    data,
    x="lot",
    y="occupancy_rate",
    color="zone",
    labels={"occupancy_rate": "占用率(%)"},
    title="各车位区域占用率对比",
    text_auto=".1f%"  # 直接在条形上显示百分比
)
fig.update_layout(yaxis_range=[0, 100])
fig.show()

内容的提问来源于stack exchange,提问作者epistemetrica

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 12:44:52