Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在matplotlib散点图中显示每种颜色的图例标签_Python_Matplotlib - Fatal编程技术网

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


检查并删除副本。也可以查看matplotlib页面。谢谢,第一个答案正是我想要的