How to customize marker colors and shapes in scatter plot?

Elham picture Elham · Dec 6, 2017 · Viewed 28k times · Source

I have a data set with 9 columns. 7 features are used for feature selection and one of them for the classification. I used tsne library for feature selection in order to see how much my data could be classified.The result from tsne is shown in picture.

However, I want to visualize my data in another way. I would like to set a color for each observation based on the column f1 (id). for example :

f1(id) f2 f3 ... f9(class label)
1      66 77 ... A
1      44 88 ... A
2      33 55 ... B
2      77 88 ..  B

colors come from f1 and shapes come from f9 . I do not know how to do it! I would appreciate for your comments or give me some references to learn more about visualization part. enter image description here this is my code:

plt.scatter(visualize_x, visualize_y, c= y,marker='^', cmap=plt.cm.get_cmap("jet", 10))

Answer

kevinkayaks picture kevinkayaks · Dec 7, 2017

Is this the type of thing you're after?

from matplotlib import pyplot as plt 

#generate a list of markers and another of colors 
markers = ["." , "," , "o" , "v" , "^" , "<", ">"]
colors = ['r','g','b','c','m', 'y', 'k']

#make a sample dataset
x = np.arange(0,10)  #test x values.. every feature gets the same x values but you can generalize this
y = [s*x for s in np.arange(7)] #generate 7 arrays of y values 


for i in range(7): #for each of the 7 features 
    mi = markers[i] #marker for ith feature 
    xi = x #x array for ith feature .. here is where you would generalize      different x for every feature
    yi = y[i] #y array for ith feature 
    ci = colors[i] #color for ith feature 
    plt.scatter(xi,yi,marker=mi, color=ci) 
plt.show() 

enter image description here