Home > Enterprise >  Color mismatch between legend and scatter plot elements
Color mismatch between legend and scatter plot elements

Time:10-12

I am unable to use the same colors in legend as coming from my cycled data. 'alldata' has a size 569x30 so defining that many colors is not feasible

for labels in ['benign', 'malignant']:
       scatter = plt.scatter(svd_pca_eqvt[:,0],svd_pca_eqvt[:,1],label=labels, c=alldata['target'])
plt.legend()

enter image description here

CodePudding user response:

You can add the colors in the for loop instead like the following:

for labels, color in zip (['benign', 'malignant'], ['#FECB52','#7E1E9C']):
       scatter = plt.scatter(svd_pca_eqvt[:,0],svd_pca_eqvt[:,1],label=labels, c=color)
plt.legend()

#FECB52 --> yellow #7E1E9C --> Dark Purple

  • Related