首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >按颜色绘制分类

按颜色绘制分类
EN

Stack Overflow用户
提问于 2020-05-30 04:48:08
回答 1查看 20关注 0票数 1

我正在绘制分割图,并且遇到了一个问题,即我的分类值只显示一种颜色。有什么建议吗?

代码语言:javascript
复制
    [![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]
EN

回答 1

Stack Overflow用户

发布于 2020-05-30 04:56:29

IIUC,你在传说中有个问题您在绘图时忘记传递图例

代码语言:javascript
复制
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 legend
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62094378

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档