数据集的图例怎么生成

数据集有13个分类,每个分类都有颜色,怎么生成色块的图例。

import matplotlib.pyplot as plt
import matplotlib.patches as mpatches

s3dis_color = [[255, 248, 220], [220, 220, 220], [139, 71, 38], [238, 197, 145], [70, 130, 180], [179, 238, 58], [110, 139, 61], [105, 105, 105], [0, 0, 128], [205, 92, 92], [244, 164, 96], [147, 112, 219], [255, 228, 225]]

labels_dict = {
    "0_ceiling": 0,
    "1_floor": 1,
    "2_wall": 2,
    "3_beam": 3,
    "4_column": 4,
    "5_window": 5,
    "6_door": 6,
    "7_table": 7,
    "8_chair": 8,
    "9_sofa": 9,
    "10_bookcase": 10,
    "11_board": 11,
    "12_clutter": 12
}

labels = labels_dict.keys()

# 创建一个图例对象
legend_elements = []
for color, label in zip(s3dis_color, labels):
    # 将RGB颜色值转换为范围在[0,1]之间的浮点数
    color = [c / 255 for c in color]
    # 创建填充颜色的矩形
    rect = mpatches.Rectangle((0, 0), 1, 1, facecolor=color)
    # 创建图例元素并添加到图例对象中
    legend_elements.append((rect, label))

# 创建图例
fig, ax = plt.subplots()

legend = ax.legend(*zip(*legend_elements), loc='center', ncol=3)


# 去除坐标轴
ax.axis('off')


# 保存图例
plt.savefig("legend.png", bbox_inches='tight', pad_inches=0)

这是S3DIS数据集的图例。

  • 7
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值