已知家居布局,layoutinfo = [ ('three-seatersofa', 494 / 2, 90 / 2, 280, 90, 0), ('tea_table',…
- User
已知家居布局,layout_info = [ ('three-seater_sofa', 494 / 2, 90 / 2, 280, 90, 0), ('tea_table', 494 / 2, (90 / 2) + (90 / 2) + 70 + (70 / 2), 140, 70, 0), ('carpet', 494 / 2, (90 / 2) + (90 / 2) + 70 + (70 / 2), 330, 330 * 0.8, 0), ('chair', (494 / 2) + (140 / 2) + (80 / 2) + 70, (90 / 2) + (90 / 2) + 70 + (70 / 2), 80, 80, 90), ('double_sofa', (494 / 2) - (140 / 2) - (140 / 2) - 70, (90 / 2) + (90 / 2) + 70 + (70 / 2), 140, 90, 270), ('side_table', (494 / 2) - (280 / 2) - (50 / 2) - 15, 90 / 2, 50, 40, 0), ('floor_lamp', (494 / 2) + (280 / 2) + (40 / 2) + 15, 90 / 2, 40, 40, 0), ('plant', 494 - (50 / 2), 606 - (50 / 2), 50, 50, 0) ] 画出该布局的草图
- Assistant
给定以下家居布局信息
layout_info,我们可以使用 Python 的matplotlib库绘制该布局的草图。下面是完整的代码:import matplotlib.pyplot as plt import matplotlib.patches as patches # 房间尺寸 room_width = 494 room_height = 606 # 布局信息 layout_info = [ ('three-seater_sofa', 494 / 2, 90 / 2, 280, 90, 0), ('tea_table', 494 / 2, (90 / 2) + (90 / 2) + 70 + (70 / 2), 140, 70, 0), ('carpet', 494 / 2, (90 / 2) + (90 / 2) + 70 + (70 / 2), 330, 330 * 0.8, 0), ('chair', (494 / 2) + (140 / 2) + (80 / 2) + 70, (90 / 2) + (90 / 2) + 70 + (70 / 2), 80, 80, 90), ('double_sofa', (494 / 2) - (140 / 2) - (140 / 2) - 70, (90 / 2) + (90 / 2) + 70 + (70 / 2), 140, 90, 270), ('side_table', (494 / 2) - (280 / 2) - (50 / 2) - 15, 90 / 2, 50, 40, 0), ('floor_lamp', (494 / 2) + (280 / 2) + (40 / 2) + 15, 90 / 2, 40, 40, 0), ('plant', 494 - (50 / 2), 606 - (50 / 2), 50, 50, 0) ] # 创建绘图 fig, ax = plt.subplots(figsize=(10, 12)) for item in layout_info: name, x, y, width, height, angle = item # 创建矩形(家具) rect = patches.Rectangle( (x - width / 2, y - height / 2), # 左下角坐标 width, height, angle=angle, edgecolor='black', facecolor='lightgrey', linewidth=1 ) ax.add_patch(rect) # 添加家具名称标签 ax.text(x, y, name, ha='center', va='center', fontsize=8, rotation=angle) # 设置房间的边框 room = patches.Rectangle((0, 0), room_width, room_height, edgecolor='black', facecolor='none', linewidth=2) ax.add_patch(room) # 设置坐标轴范围 ax.set_xlim(-50, room_width + 50) ax.set_ylim(-50, room_height + 50) ax.set_aspect('equal') # 隐藏坐标轴 ax.axis('off') # 显示绘图 plt.show()