plt绘制 2维、3维散点图

# 3维
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets.samples_generator import make_classification
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = Axes3D(fig)
data,labels=make_classification(n_samples=1000,n_features=3,n_redundant=0,n_informative=2,
random_state=1,n_clusters_per_class=2) unique_lables=set(labels)
colors=plt.cm.Spectral(np.linspace(0,1,len(unique_lables)))
for k,col in zip(unique_lables,colors):
x_k=data[labels==k]
ax.scatter3D(x_k[:,0],x_k[:,1],x_k[:, 2], c=col) # 开始绘制,x_k[:,0] 表示取第一维 plt.title('data by make_classification()')
plt.show()
# 2维

import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets.samples_generator import make_classification
data,labels=make_classification(n_samples=100,n_features=2,n_redundant=0,n_informative=2,
random_state=5,n_clusters_per_class=2)
unique_lables=set(labels)
colors=plt.cm.Spectral(np.linspace(0,1,len(unique_lables)))
for k,col in zip(unique_lables,colors):
x_k=data[labels==k]
plt.plot(x_k[:,0],x_k[:,1],'o',markerfacecolor=col,markeredgecolor="k",
markersize=10)
plt.title('data by make_classification()')
plt.show()
上一篇:memset struct含有string的崩溃


下一篇:集群负载均衡LVS