Python 在matplotlib散点图中显示每种颜色的图例标签
我想使用Python 在matplotlib散点图中显示每种颜色的图例标签,python,matplotlib,Python,Matplotlib,我想使用class\u 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.s
class\u 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()
除了以下方法外,还有其他方法可以做到这一点:
- 将每个类的X、Y值过滤到3个单独的列表中,并创建3个散点图
- 加载颜色映射,计算每个标签的颜色,并从
Patches