数据集的图例怎么生成

数据集有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数据集的图例。

相关推荐

  1. 图像数据扩展

    2024-04-24 23:52:02       60 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-24 23:52:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-24 23:52:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-24 23:52:02       87 阅读
  4. Python语言-面向对象

    2024-04-24 23:52:02       96 阅读

热门阅读

  1. C++:函数符(一)

    2024-04-24 23:52:02       33 阅读
  2. swift语言学习总结

    2024-04-24 23:52:02       27 阅读
  3. Qt 运行 Android 程序时找不到 Toou2D 库闪退

    2024-04-24 23:52:02       29 阅读
  4. c# 值类型和引用类型的区别

    2024-04-24 23:52:02       32 阅读
  5. [杂谈] [杂谈]老实人要突破的想法,显眼包?

    2024-04-24 23:52:02       32 阅读
  6. python常见语法

    2024-04-24 23:52:02       37 阅读
  7. windows命令行安装wget

    2024-04-24 23:52:02       38 阅读
  8. 查看iOS应用的ipa包构建版本6种方法

    2024-04-24 23:52:02       38 阅读
  9. 【k8s】:Pod的生命周期详解

    2024-04-24 23:52:02       34 阅读
  10. Stable Diffusion插件(翻译)

    2024-04-24 23:52:02       27 阅读
  11. [普及][NOIP1998 普及组] 三连击

    2024-04-24 23:52:02       34 阅读