python - Sklearn matplotlib coloring clusters by unique values in figure and showing labels that correspond to these cluster colors -
i want set label/legend correspond colors of clusters after running pca. ex. here clusters colored value 1-4.
**see attached image
1) want have legend shows group of values correspond 1-4 value. tried np.unique() , did not work.
2) also, coloring clusters lets bmi, how can set range group them , still show legend of color ranges?
data = pd.read_table('test.txt', header=none) data.columns = ['age', 'score', 'asa', 'bmi'] pandas.tools.plotting import scatter_matrix #_ = pd.scatter_matrix( data, figsize=(30,30)) pca = pca(n_components=data.shape[1]) pca.fit(data) data_pca = pca.transform(data) fig = plt.figure( figsize=(24,8)) ax1 = fig.add_subplot(131) ax2 = fig.add_subplot(132) ax3 = fig.add_subplot(133) ax1.scatter( data_pca[:,0], data_pca[:,1], alpha=0.5, s=25, c=data.asa) ax2.scatter( data_pca[:,2], data_pca[:,1], alpha=0.5, s=25, c=data.asa) ax3.scatter( data_pca[:,2], data_pca[:,3], alpha=0.5, s=25, c=data.asa,label=np.unique(data.asa)) plt.legend(loc = 'right') plt.show()
Comments
Post a Comment