我正在绘制分割图,并且遇到了一个问题,即我的分类值只显示一种颜色。有什么建议吗?
[![fig = plt.figure(figsize = (20,10))
ax = fig.add_subplot(1,1,1)
ax.set_xlabel('Sentiment Score', fontsize = 15)
ax.set_ylabel('Star Review', fontsize = 15)
ax.set_title('Heinz Segmentation', fontsize = 20)
targets = \['Sugar/ Healthy Positives', 'Sugar/ Healthy Negatives', 'Price/ Value Positives', 'Price/ Value Negatives', 'Purists Positives', 'Purists Negatives'\]
colors = \['r', 'g', 'b', 'c', 'm', 'y'\]
for target, color in zip(targets,colors):
ax.scatter(df.Compound,df.StarsInt
, c = color
, s = 200
,alpha = .5)
ax.legend(targets, prop={'size': 14})
ax.grid()][1]][1]发布于 2020-05-30 04:56:29
IIUC,你在传说中有个问题您在绘图时忘记传递图例
for target, color in zip(targets,colors):
ax.scatter(df.Compound,df.StarsInt, c=color,
s = 200,alpha = .5,
label=target) # <--- pass the label to show in legendhttps://stackoverflow.com/questions/62094378
复制相似问题