在matplotlib散点图中显示每种颜色的图例标签

时间:2019-10-28 16:27:10

标签: python matplotlib

我想使用class_titles中的值为散点图中的每种颜色在图例中生成一个项目

import matplotlib.pyplot as plt

classes = [0, 1, 2, 0, 1, 1, 2]
x = [0, 1, 2, 0, 1.3, 1.5, 2.2]
y = [.5, 1, 2, .9, 1.2, 1.2, 2.1]

class_titles = ['first', 'second', 'third']

plt.scatter(x, y, c=labels, cmap='gist_rainbow')
plt.show()

scatter plot

除了:

,还有其他方法可以做到吗?
  • 将每个类别的X,Y值过滤到3个单独的列表中,并创建3个散点图

  • 加载颜色图,找出每个标签的颜色,并从Patches

  • 创建自定义图例

0 个答案:

没有答案