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)
这是您所追求的类型吗?
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)
| 归档时间: |
|
| 查看次数: |
12292 次 |
| 最近记录: |