gpt4 book ai didi

python - 带有由 c 选项指定的颜色标签和图例的 matplotlib 散点图

转载 作者:太空宇宙 更新时间:2023-11-03 12:43:56 26 4
gpt4 key购买 nike

<分区>

我想制作 this kind of scatter plot其中点的颜色由“c”选项指定,图例显示颜色的含义。

我的数据源如下:

scatter_x = [1,2,3,4,5]
scatter_y = [5,4,3,2,1]
group = [1,3,2,1,3] # each (x,y) belongs to the group 1, 2, or 3.

我试过这个:

plt.scatter(scatter_x, scatter_y, c=group, label=group)
plt.legend()

很遗憾,我并没有如愿得到图例。如何正确显示图例?我预计有五行,每行显示颜色和组对应关系。

enter image description here

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com