Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize marker colors and shapes in scatter plot? [duplicate]

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))
like image 423
Elham Avatar asked Dec 06 '17 22:12

Elham


1 Answers

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

like image 130
kevinkayaks Avatar answered Sep 29 '22 16:09

kevinkayaks