I'm trying to set the legend according to categorical values set for color but it's not working.
import matplotlib.pyplot as plt
colors = finalDf['sales'].astype('category').cat.codes
scatter = plt.scatter(x= finalDf['principal component 1'],
y= finalDf['principal component 2'],
c = finalDf['sales'].astype('category').cat.codes)
plt.xlabel('PC1')
plt.ylabel('PC2')
plt.legend(labels=list(finalDf['sales'].unique()))
plt.show()
(https://i.stack.imgur.com/YwSoG.png)
I tried various combinations of the 'sales' data columns but it was in vain. I want to know if there is a solution other than using seaborn library as the task recquires matplotlib. Thank you