繁体   English   中英

将颜色条添加到 seaborn 气泡图中

[英]Adding colorbar to seaborn bubble plot

我正在尝试根据我的值的 interval_size 来添加颜色条,在尝试使用 seaborn 图时遇到了以下错误的问题:

AttributeError: 'AxesSubplot' object has no attribute 'get_array'

当前情节

在此处输入图片说明

想要的情节

在此处输入图片说明

数据表

min            max          y    interval_size   y_pred     split
0.654531    1.021657    0.837415    0.367126    0.838094    train
0.783401    1.261898    1.000000    0.478497    1.022649    valid
-0.166070   0.543749    0.059727    0.709819    0.188840    train
0.493270    1.112610    0.504393    0.619340    0.802940    valid
0.140510    0.572957    0.479063    0.432447    0.356734    train

绘图代码

plt.figure(figsize=(16,8))

plots = sns.scatterplot(x="y", 
                y="y_pred",
                #size= "interval_size",            
                data=df,
                alpha=0.65,
                c=df['interval_size'],
                cmap='viridis', 
                #hue = 'split',
                s = (df['interval_size']**2)*50,
                style = 'split',
                markers = {'train': '^', 'valid':'8'}
               )
# Put the legend out of the figure
#plt.legend(bbox_to_anchor=(1.01, 1),borderaxespad=0, title='Data Split', fontsize=20)

##Add Colorbar
plt.colorbar(plots)


#Plot Characteristics
plt.title("Stability: True vs Predicted Labels", fontsize = 36)
plt.xlabel("True Labels", fontsize = 25)
plt.ylabel("Predicted Labels", fontsize = 25)

我无法重现你的情节是因为我的方式c不工作sns.scatterplot ,因此我必须使用hue来代替。 但是我使用hue进行了测试,以下解决方案对我有用:

bar = plots.get_children()[3] 
plt.colorbar(mappable=bar)

您的另一个选择是使用plt.scatter而不是sns.scatterplot

[编辑]根据下面的评论,使用c而不是hue解决方案可能适用于:

bar = plots.get_children()[2] 
plt.colorbar(mappable=bar)

暂无
暂无

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

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