def plot(data, inverselengthscale, labels, name_out_file, title): # most_dominants = Utility.get_input_sensitivity(inverselengthscale, 2) # x = data[ :, 0 ] # y = data[ :, 1 ] x = data[:, 0] y = data[:, 2] label = map(int, labels) label = np.array(labels) print set(labels) # colors = ['red','green','blue','purple'] if len(labels) > 1000: ind = np.random.choice(len(labels), 1000) x = x[ind] y = y[ind] labels = labels[ind] colors = Utility.get_color_map(len(set(labels))) plt.clf() # plt.scatter(x, y, c=labels, cmap=matplotlib.colors.ListedColormap(colors)) for idx, s in enumerate(sorted(set(labels))): plt.scatter(x[labels == s], y[labels == s], c=colors[idx], label=s) plt.legend() plt.title(title) plt.savefig(name_out_file)
def plot(data, inverselengthscale, labels): most_dominants = Utility.get_input_sensitivity(inverselengthscale, 2) x = data[ :, most_dominants[0] ] y = data[ :, most_dominants[1] ] label = map(int, labels) label = np.array(labels) print set(labels) colors = Utility.get_color_map(len(set(labels))) plt.clf() for idx, s in enumerate(set(labels)): print s plt.scatter(x[labels==s], y[labels==s], c=colors[idx] , label=s) plt.legend() plt.savefig( './dbscan_test.eps' )
def plot(data, inverselengthscale, labels, name_out_file, title): most_dominants = Utility.get_input_sensitivity(inverselengthscale, 2) x = data[ :, most_dominants[0] ] y = data[ :, most_dominants[1] ] label = map(int, labels) label = np.array(labels) # print set(labels) # colors = ['red','green','blue','purple'] colors = Utility.get_color_map(len(set(labels))) plt.clf() # plt.scatter(x, y, c=labels, cmap=matplotlib.colors.ListedColormap(colors)) for idx, s in enumerate( sorted( set(labels)) ): plt.scatter(x[labels==s], y[labels==s], c=colors[idx] , label=s) plt.legend() plt.title(title) plt.savefig( name_out_file )
def plot(x, y, outpath, label_list=None, color=None, alpha=0.5, bivariate=False, X_bi=None, Y_bi=None, title=None, xlim=None, ylim=None, cmap=None): plt.clf() if label_list is not None: lab = set(label_list) lab = list(lab) # print lab lab.sort(reverse=True) label_list = np.asarray(label_list) if color is None: color = ['r', 'b', 'g'] color = Utility.get_color_map(len(lab)) color.reverse() for idx, l in enumerate(lab): # print label_list == l plt.scatter(x[label_list == l], y[label_list == l], label=l, color=color[idx] ,alpha=0.5, cmap=cmap) else : plt.scatter(x, y, alpha=0.5, c=color, cmap=cmap) if bivariate: delta = 0.025 xx = np.arange(np.amin(X_bi), np.amax(X_bi), delta) yy = np.arange(np.amin(Y_bi), np.amax(Y_bi), delta) # xx = np.arange(-1.0, 1.0, delta) # yy = np.arange(-1.0, 1.0, delta) mux = np.mean(X_bi) muy = np.mean(Y_bi) sigmax = np.sqrt(np.cov(X_bi,Y_bi)[0][0]) sigmay = np.sqrt(np.cov(X_bi,Y_bi)[1][1]) sigmaxy = np.cov(X_bi,Y_bi)[0][1] print mux, muy, sigmax, sigmay, sigmaxy # xx = np.arange(mux-2*sigmax, mux+2*sigmax, delta) # yy = np.arange(muy-2*sigmay, muy+2*sigmay, delta) X, Y = np.meshgrid(xx, yy) Z = mlab.bivariate_normal(X, Y, sigmax=sigmax, sigmay=sigmay, mux=mux, muy=muy, sigmaxy=sigmaxy) # print Z plt.contour(X, Y, Z) if title is not None: plt.title(title) plt.legend() if xlim: plt.xlim(xlim) if ylim: plt.ylim(ylim) print plt.xlim(), plt.ylim() plt.savefig(outpath) pass