i trying add legend graph in matplotlib. instead of creating legend puts full list of mylabels in legend.
the legend cut off , cant see more that, assume due size.
this code:
features2 = ["number of sides"] features3 = ["largest angle"] header2 = ["label"] data_df = pd.dataframe.from_csv("allmixedshapes2.csv") x1 = np.array(data_df[features2].values) y1 = np.array(data_df[features3].values) l = np.array(data_df[header2].values) plt.scatter(x1[:, 0],y1, c=y, cmap=plt.cm.paired, label=l) plt.axis([0, 17, 0, 200]) plt.ylabel("maximum angle (degrees)") plt.xlabel("number of sides") plt.title('original 450 test shapes') plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.) plt.show()
and allmixedshapes2.csv looks this:
i'm quite new python , machine learning , ive tried other examples cant work.
matplotlib's label
argument meant single string labels entire dataset, rather array of individual labels points within dataset. if wish pass array of point-by-point labels aggregated legend, best option seaborn library. seaborn provides wrapper around matplotlib more convenient statistical visualization.
this should approximately wish data:
import seaborn seaborn.lmplot('number of sides', 'largest angle', hue='label', data=data_df, fit_reg=false)
i'd suggest checking out seaborn example gallery more ideas.
Comments
Post a Comment