Python 如何更改图例中散点的颜色?

Python 如何更改图例中散点的颜色?,python,python-2.7,matplotlib,pandas,Python,Python 2.7,Matplotlib,Pandas,我正在从pandas数据帧创建一个数据散点图,并希望强调散点图中的一个特定点 现在,我的代码是: plt.scatter(x_cors, y_cors, s=50, color=colors) plt.legend(['name'], scatterpoints=1, loc="lower left", fontsize=10) plt.show() 在我的颜色数组中,每个元素都是黄色的,只有一个点是绿色的。在我的图例中,我想解释什么是绿点,但绿点总是显示为黄色。有没有办法手动将其更改为绿色

我正在从pandas数据帧创建一个数据散点图,并希望强调散点图中的一个特定点

现在,我的代码是:

plt.scatter(x_cors, y_cors, s=50, color=colors)
plt.legend(['name'], scatterpoints=1, loc="lower left", fontsize=10)
plt.show()

在我的颜色数组中,每个元素都是黄色的,只有一个点是绿色的。在我的图例中,我想解释什么是绿点,但绿点总是显示为黄色。有没有办法手动将其更改为绿色

您可以使用不同的颜色绘制该点:

plt.scatter([x], [y], color='g') # Replace x and y to the coordinate you want

您可能必须将颜色元素定义为
'g'
'y'
,而不是
绿色
黄色
或仅
g
y

相反,最简单的方法是从数组中省略绿色数据点,并给它一个新数组,例如
x\u cors\u green,y\u cors\u green=[?,?]
。然后,您可以简单地添加另一个散点:

plt.scatter(x_cors, y_cors, s=50, color='y')
plt.scatter(x_cors_green, y_cors_green, s=50, color='g')
plt.legend(['name'], scatterpoints=1, loc="lower left", fontsize=10)
plt.show()