figure.add_subplot (1,1,1) не отображается в окне графика Spyder - PullRequest
0 голосов
/ 14 февраля 2020

Я работаю над алгоритмом K Means

ниже приведен код для построения образцов и центроидов, и я пытаюсь построить то же самое, используя add_subplot

fig = plt.figure(figsize=(6, 4))

# Colors uses a color map, which will produce an array of colors based on
# the number of labels there are. We use set(k_means_labels) to get the unique labels.
colors = plt.cm.Spectral(np.linspace(0, 1, len(set(k_means_labels))))

# Create a plot
dx = fig.add_subplot(1, 1, 1)

# For loop that plots the data points and centroids.
# k will range from 0-3, which will match the possible clusters that each data point is in.

for k, col in zip(range(len([[4,4], [-2, -1], [2, -3], [1, 1]])), colors):

    # Create a list of all data points, where the data points that are 
    # in the cluster (ex. cluster 0) are labeled as true, else they are
    # labeled as false.
    my_members = (k_means_labels == k)

    # Define the centroid, or cluster center.
    cluster_center = k_means_cluster_centers[k]

    # Plots the datapoints with color col.
    dx.plot(X[my_members, 0], X[my_members, 1], 'w', markerfacecolor=col, marker='.')

    # Plots the centroids with specified color, but with a darker outline
    dx.plot(cluster_center[0], cluster_center[1], 'o', markerfacecolor=col,  markeredgecolor='k', markersize=6)

# Title of the plot
dx.set_title('KMeans')

# Remove x-axis ticks
dx.set_xticks(())

# Remove y-axis ticks
dx.set_yticks(())

# Show the plot
plt.show()

first time the plot worked properly. but second time onwards the below syntax is not showing anything in the plot window in Ipython console in Spyder

dx = fig.add-subplot(1,1,1)

Я перезапустил шпион , перезапустил консоль i python и перезагрузил систему. никто из них не работал.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...