python plt 颜色标签

python plt color label

# x,y,size 데이터 셋팅
x = target_data.accuracy
y =  target_data.f1_score
s = target_data.recall

# 라벨셋팅(순서유의)
users =['dnn', 'random forest', 'extra trees', 'ensemble']

这是一个有疑问的地方。

# 컬러셋팅
colors =  list(np.array([0.81520346,0.28735556, 0.6542928, 0.3542928]))
df = pd.DataFrame(dict(accuracy=x, f1_score=y, users=users, s=s, c=colors ))

# 그래프 그리기
ax = df.plot.scatter(x='accuracy', y='f1_score', s=df.s*10,c= df.c,  alpha=0.5)
for i, txt in enumerate(users):
    ax.annotate(txt, (df.accuracy.iat[i],df.f1_score.iat[i]))
plt.show()

我确定设置了颜色数组并匹配了图形

生成的图像带有图形和标签,格式正确,但颜色表示为黑白图像。 怎么了?

没有什么不对,但是你的cmap (Colormap) defaults to a color map where numbers map to opacity. You could change it to whatever you like from this long list: https://matplotlib.org/examples/color/colormaps_reference.html并且得到了一个非常丰富多彩的情节

ax = df.plot.scatter(x='accuracy', y='f1_score', s=df.s*10,c= df.c, 
                 alpha=0.5, cmap='PuOr') # added cmap

如果您仅使用标量数字进行颜色设置,它将映射到颜色图,默认情况下为 rc image.cmap - 默认情况下为灰度。因此,您可以另外设置另一个颜色图(例如 cmap='viridis' 或其他),或者将颜色定义为颜色名称、rgb(a) 元组或 rgb 十六进制值:

示例:

colors = ['r', 'g', 'b', 'm']
colors = [[.2, .3, .4], [.7, .3, .4], [.2, .9, .4], [.2, .3, .0]]
colors = ['#a0ff45', '#123456', '#fedcba', '#00ff77']