我有此数据帧diamonds,它由被等变量(carat, price, color),我想画的散点图price来carat为每个color,这意味着不同的color具有在图中不同的颜色.
这很容易在R与ggplot:
ggplot(aes(x=carat, y=price, color=color), #by setting color=color, ggplot automatically draw in different colors
data=diamonds) + geom_point(stat='summary', fun.y=median)
Run Code Online (Sandbox Code Playgroud)

我想知道如何在Python中使用matplotlib?
PS:
我知道辅助绘图包,比如seaborn和ggplot for python,我不喜欢它们,只是想知道是否有可能matplotlib单独使用,P;
我想用这个片段将图例添加到我的情节中:
import matplotlib.pylab as plt
fig = plt.figure()
axes = fig.add_axes([0.1, 0.1, 0.8, 0.8]) # left, bottom, width, height (range 0 to 1)
axes.set_xlabel('x (m)')
axes.set_ylabel('y (m)')
for i, representative in enumerate(representatives):
axes.plot([e[0] for e in representative], [e[1] for e in representative], color='b', label='Representatives')
axes.scatter([e[0] for e in intersections], [e[1] for e in intersections], color='r', label='Intersections')
axes.legend()
Run Code Online (Sandbox Code Playgroud)
我最终得到了这个情节

显然,这些项目在图中是重复的.我该如何更正此错误?