python 2.7 - Different colors for scatter plots based on origin of data -


i have list called 'samples', loading several images list 2 different folders, let's folder1 , folder2. convert list dataframe , plot them in 2d scatter plot. want scatter plot show contents folder1 red color , contents folder2 in blue color. how can accomplish this. code below:

    samples = []     folder1 = glob.iglob('/home/..../folder1/*.png')     folder2 = glob.iglob('/home/..../folder2/*.png')      fname in folder1:         img = misc.imread(fname)         samples.append((img[::2, ::2] / 255.0).reshape(-1))      fname in folder2:         img = misc.imread(fname)         samples.append((img[::2, ::2] / 255.0).reshape(-1))      samples = pd.dataframe(samples)      def do_iso(df):         sklearn import manifold         iso = manifold.isomap(n_neighbors=6, n_components=3)         iso.fit(df)         = iso.transform(df)         return      def plot2d(t, title, x, y):         fig = plt.figure()         ax = fig.add_subplot(111)         ax.set_title(title)         ax.set_xlabel('component: {0}'.format(x))         ax.set_ylabel('component: {0}'.format(y))         x_size = (max(t[:,x]) - min(t[:,x])) * 0.08         y_size = (max(t[:,y]) - min(t[:,y])) * 0.08         ax.scatter(t[:,x],t[:,y], marker='.',alpha=0.7)      plot2d(do_iso(samples), 'iso_chart', 0, 1)      plt.show() 

it's pretty difficult without seeing arrays working with. plotting result of do_iso() function, creates array using sklearn.manifold.isomap.transform().

does function preserves ordering of elements in array? if so, things easy. first filling images folder1 , folder2, count number of items in folder1, , split array in 2 based on number (eg. nbfilesfolder1). 2 calls scatter:

ax.scatter(t[:nbfilesfolder1,x],t[:nbfilesfolder1,y], marker='.',alpha=0.7, c='red') ax.scatter(t[nbfilesfolder1:,x],t[nbfilesfolder1:,y], marker='.',alpha=0.7, c='blue') 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -