简体   繁体   English

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']

This is a questionable point. 这是一个值得怀疑的观点。

# 컬러셋팅
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()

I definitely set the color array and matched the graph. 我肯定设置了颜色数组并匹配了图形。

The resulting image is well-formed with graphs and labels, but the color is represented as a black and white image. 生成的图像带有图形和标签,格式良好,但是颜色表示为黑白图像。 What's wrong? 怎么了?

Nothing is wrong, but your cmap (Colormap) defaults to a color map where numbers map to opacity. 没错,但是您的cmap (颜色映射)默认为颜色映射,其中数字映射为不透明度。 You could change it to whatever you like from this long list: https://matplotlib.org/examples/color/colormaps_reference.html and get a very colorful plot 您可以从以下长长的列表中将其更改为所需的任何内容: 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

多彩散点图

If you use just scalar numbers for color setting, it will map to a colormap, which is by default rc image.cmap - and this is grayscale by default. 如果仅将标量数字用于颜色设置,它将映射到一个颜色图,默认情况下为rc image.cmap默认情况下为灰度。 So you can either additionally set another colormap (like eg cmap='viridis' or whatever), or you define your colors as color names, rgb(a) tuples or rgb hex values: 因此,您可以另外设置另一个颜色图(例如cmap='viridis'或其他颜色),或将颜色定义为颜色名称,rgb(a)元组或rgb十六进制值:

Examples: 例子:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM