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

Python DataFrame计算建筑楼层荷载高度表格总值及输出图像需求

计算建筑楼层荷载与高度总值并实现可视化

嘿,我来帮你搞定这个问题——咱们先把核心的总值算出来,再用可视化把数据直观展示出来,这样结构分析的时候也能一目了然。

第一步:计算核心总值

你的数据字典已经整理得很清楚了,先提取数据计算总恒载和总建筑高度:

building_weight_and_height = {
    'Floor': ['Roof','10th','9th','8th','7th','6th','5th','4th','3rd','2nd'],
    'DL(kN)': [1200]*10,  # 简化写法,因为所有恒载值都是1200
    'StoreyHeight': [3]*9 + [4]
}

# 计算总恒载
total_dead_load = sum(building_weight_and_height['DL(kN)'])
# 计算总建筑高度
total_building_height = sum(building_weight_and_height['StoreyHeight'])

print(f"总恒载:{total_dead_load} kN")
print(f"总建筑高度:{total_building_height} m")

运行这段代码后,你会得到:

总恒载:12000 kN
总建筑高度:31 m

第二步:可视化展示

用Python的matplotlib就能轻松做出直观的图表,我给你写了一段代码,能同时展示各楼层的荷载、层高分布,还有从底层到各楼层的累积高度:

import matplotlib.pyplot as plt
import numpy as np

# 提取数据
floors = building_weight_and_height['Floor']
dl_values = building_weight_and_height['DL(kN)']
storey_heights = building_weight_and_height['StoreyHeight']

# 计算累积高度(注意楼层顺序是从屋顶到底层,所以要反转后计算)
cumulative_heights = np.cumsum(storey_heights[::-1])

# 创建画布,分成左右两个子图
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 6))

# 左图:各楼层恒载与层高对比
x_axis = np.arange(len(floors))
bar_width = 0.35

# 绘制恒载柱状图
dl_bars = ax1.bar(x_axis - bar_width/2, dl_values, bar_width, label='恒载 (kN)', color='#3498db')
# 绘制层高柱状图
height_bars = ax1.bar(x_axis + bar_width/2, storey_heights, bar_width, label='层高 (m)', color='#2ecc71')

# 设置左图的标签和标题
ax1.set_xticks(x_axis)
ax1.set_xticklabels(floors)
ax1.set_title('各楼层恒载与层高分布')
ax1.legend()

# 给柱状图添加数值标签
for bar in dl_bars:
    height = bar.get_height()
    ax1.annotate(f'{height}',
                xy=(bar.get_x() + bar.get_width()/2, height),
                xytext=(0, 3),
                textcoords='offset points',
                ha='center', va='bottom')

for bar in height_bars:
    height = bar.get_height()
    ax1.annotate(f'{height}',
                xy=(bar.get_x() + bar.get_width()/2, height),
                xytext=(0, 3),
                textcoords='offset points',
                ha='center', va='bottom')

# 右图:从底层到各楼层的累积高度
ax2.barh(floors[::-1], cumulative_heights, color='#9b59b6')
# 添加总高度的参考线
ax2.axvline(total_building_height, color='#e74c3c', linestyle='--', label=f'总高度: {total_building_height} m')

# 设置右图的标签和标题
ax2.set_title('从底层到各楼层的累积高度')
ax2.set_xlabel('累积高度 (m)')
ax2.legend()

# 给累积高度添加数值标签
for idx, val in enumerate(cumulative_heights):
    ax2.annotate(f'{val} m',
                xy=(val, idx),
                xytext=(5, 0),
                textcoords='offset points',
                ha='left', va='center')

# 调整子图间距
plt.tight_layout()
plt.show()

运行这段代码后,你会得到一个清晰的可视化图:

  • 左侧子图能一眼看到所有楼层的恒载都是1200kN,只有2层的层高是4m,其余都是3m;
  • 右侧子图展示了从2层(底层)往上到每个楼层的累积高度,虚线标记出了总高度31m,非常适合结构设计时参考。

额外补充

如果需要计算从屋顶到各楼层的累积荷载(比如做竖向荷载分析时用),可以用这段代码:

cumulative_dl = np.cumsum(dl_values)
print("从屋顶到各楼层的累积荷载:", cumulative_dl)

这样就能得到从屋顶开始向下的累积荷载序列,方便后续的结构计算。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 10:10:47