装箱算法中如何将小矩形重新排列成大矩形

2024-04-26 07:40:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python新手,我正在尝试从原始数据重新排列矩形。我正在使用装箱算法,我想用下面的颜色对它进行排序。需要帮忙吗

现在输出:

enter image description here

预期产出:

enter image description here


Tags: 算法原始数据排序颜色矩形新手装箱
1条回答
网友
1楼 · 发布于 2024-04-26 07:40:58

代码中有一些小的更改,请按照以下代码执行一次:

    import matplotlib.pyplot as plt
    from matplotlib.patches import Rectangle
    fig = plt.figure() 
    ax = fig.add_subplot(111) 

    temp_y=0
    i=0
    layout_height = 300
    layout_width = 300

    ax.set_xlim([0, layout_height])
    ax.set_ylim([0, layout_width])

    area_height = [80, 75, 50, 60, 52, 72, 100, 120, 150]
    area_width = [50, 46, 52, 52, 50, 48, 25, 40, 48]

    for (i,j) in zip(area_height, area_width):
       print(i,j)
       ax.add_patch(Rectangle((0, temp_y), float(j), float(i),edgecolor ='black',facecolor = 'red'))
       temp_y = temp_y + float(i)

相关问题 更多 >