I am almost done with my first real deal python data science project. However, there is one last thing I can't seem to figure out. I have the following code to create a plot for my PCA and K Means clustering algorithm:
y_axis = passers_pca_kmeans['Component 1']
x_axis = passers_pca_kmeans['Component 2']
plt.figure(figsize=(10,8))
sns.scatterplot(x_axis, y_axis, hue=passers_pca_kmeans['Segment'], palette=['g','r','c','m'])
plt.title('Clusters by PCA Components')
plt.grid(zorder=0,alpha=.4)
texts = [plt.text(x0,y0,name,ha='right',va='bottom') for x0,y0,name in zip(
passers_pca_kmeans['Component 2'], passers_pca_kmeans['Component 1'], passers_pca_kmeans.name)]
adjust_text(texts)
plt.show
- I finally got the correct code to annotate the points using
adjustText
, but my plot has too many points to label them all; it looks like a mess with text everywhere. - I would like to annotate the scatterplot based on the value in the column
'Segment'
.- The values in this column are the names of my four clusters
'first'
,'second'
,'third'
,'fourth'
.
- The values in this column are the names of my four clusters
- How do I alter my
adjustText
code to only annotate points where'Segment'='first'
?- Would this be an
np.where
situation?
- Would this be an