如何自定义散点图中的标记颜色和形状?

Elh*_*ham 3 python matplotlib markers scatter-plot

我有一个9列的数据集。7个特征用于特征选择,其中之一用于分类。我使用tsne库进行特征选择,以查看可以对我的数据进行多少分类.tsne的结果如图所示。

但是,我想以另一种方式可视化我的数据。我想基于列f1(id)为每个观察值设置颜色。例如 :

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

颜色来自f1,形状来自f9。我不知道怎么做!对于您的评论,我将不胜感激,或者给我一些参考以了解有关可视化部分的更多信息。 在此处输入图片说明 这是我的代码:

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

kev*_*aks 9

这是您所追求的类型吗?

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() 
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

  • 我认为可以肯定地说,有了这个含糊的答复,我根本无法尝试为您提供进一步的帮助。你需要什么? (2认同)
  • 我了解您有七个类别,每个类别都有一组(x,y,c),其中x,y是平面中的坐标,而c是0或1,那么您需要为每个类别使用不同的颜色和标记。还是您要为每个类别使用不同的标记,并为每个c使用不同的颜色? (2认同)