欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

view_init(elev,azim)函数的使用

程序员文章站 2022-07-13 10:46:04
...

转换视角进行观察,通过设置view_init(elev,azim)两个参数变化时,观察图像的变化

# #############################################################################
# Compute clustering
print("Compute unstructured hierarchical clustering...")
st = time.time()

#  指定分成的簇的个数为6
n_clusters=6
ward = AgglomerativeClustering(n_clusters=n_clusters, linkage='ward').fit(X)
elapsed_time = time.time() - st
label = ward.labels_
print("unstructured hierarchical clusters:: %i" % n_clusters)
print("Elapsed time: %.2fs" % elapsed_time)
print("Number of points: %i" % label.size)

# #############################################################################
# Plot result

fig = plt.figure(figsize=(14, 14))

ax = p3.Axes3D(fig)
ax.view_init(7, -80)
for l in np.unique(label):
    ax.scatter(X[label == l, 0], X[label == l, 1], X[label == l, 2],
               color=plt.cm.jet(np.float(l) / np.max(label + 1)),
               s=24, edgecolor='k')
plt.title('Without connectivity constraints (time %.2fs)' % elapsed_time)


# #############################################################################
# Define the structure A of the data. Here a 10 nearest neighbors
from sklearn.neighbors import kneighbors_graph
connectivity = kneighbors_graph(X, n_neighbors=10, include_self=False)

# #############################################################################
# Compute clustering
print("Compute structured hierarchical clustering...")
st = time.time()
ward = AgglomerativeClustering(n_clusters=n_clusters, connectivity=connectivity,
                               linkage='ward').fit(X)
elapsed_time = time.time() - st
label = ward.labels_
print("structured hierarchical clusters: %i" % n_clusters)
print("Elapsed time: %.2fs" % elapsed_time)
print("Number of points: %i" % label.size)

# #############################################################################
# Plot result
fig = plt.figure(figsize=(14, 14))

ax = p3.Axes3D(fig)
ax.view_init(7, -80)
for l in np.unique(label):
    ax.scatter(X[label == l, 0], X[label == l, 1], X[label == l, 2],
               color=plt.cm.jet(float(l) / np.max(label + 1)),
               s=24, edgecolor='k')
plt.title('With connectivity constraints (time %.2fs)' % elapsed_time)

plt.show()

view_init(elev,azim)函数的使用
view_init(elev,azim)函数的使用

将角度设置为45,0,再次进行观察
ax.view_init(45, 0)

view_init(elev,azim)函数的使用
view_init(elev,azim)函数的使用

ax.view_init(45, 45)

view_init(elev,azim)函数的使用
view_init(elev,azim)函数的使用