爱吃麻辣香锅的阿涛
2022-04-15 10:29
采纳率: 71.4%
浏览 70

matplotlib.pyplot跳错 明明有ylabel 为什么报错?

问题遇到的现象和发生背景

AttributeError: module 'matplotlib.pyplot' has no attribute 'ylable'. Did you mean: 'table'?

问题相关代码,请勿粘贴截图
import matplotlib.pyplot as plt
import numpy as np
from sklearn.cluster import KMeans
from sklearn.datasets import load_iris

iris = load_iris()
X = iris.data[:, 2:]
# 绘制数据分布图
plt.scatter(X[:, 0], X[:, 1], c="red", marker='o', label='see')
plt.xlabel('petal length')
plt.ylabel('petal width')
plt.legend(loc=2)
plt.show()

estimator = KMeans(n_clusters=3)  # 构造聚类器
estimator.fit(X)  # 聚类
label_pred = estimator.labels_  # 获取聚类标签
# 绘制K-Means结果
x0 = X[label_pred == 0]
x1 = X[label_pred == 1]
x2 = X[label_pred == 2]
plt.scatter(x0[:, 0], x0[:, 1], c="red", marker='o', label='label0')
plt.scatter(x1[:, 0], x1[:, 1], c="green", marker='*', label='label1')
plt.scatter(x2[:, 0], x2[:, 1], c="blue", marker='+', label='label2')
plt.xlabel('petal length')
plt.ylabel('petal width')
plt.legend(loc=2)
plt.show()


运行结果及报错内容

Traceback (most recent call last):
File "C:\Users\Administrator\PycharmProjects\test\main2.py", line 26, in
plt.ylable('petal width')
AttributeError: module 'matplotlib.pyplot' has no attribute 'ylable'. Did you mean: 'table'?

我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题