matplotlit绘制图像出现空白怎么解决?

python用matplotlib,sklearn绘制图像,绘制出鸢尾花图像,代码运行绘制不出来图像,是一片空白。正确图片如下图。
matplotlit绘制图像出现空白怎么解决?


from sklearn import datasets

from sklearn import svm

from sklearn.decomposition import PCA

from matplotlib import pyplot as plt

from matplotlib import patches as pch

from mpl_toolkits.mplot3d import Axes3D

import matplotlib

plt.rcParams['font.sans-serif'] = ['SimHei'] # 设置正常的中文字体

# matplotlib.rcParams['font.family'] = 'SimHei'

matplotlib.rcParams['font.size'] = 10

matplotlib.rcParams['axes.unicode_minus'] = False

v_iris = datasets.load_iris() # 加载数据赋值给变量

x = v_iris.data[:, 0] # 取数据集第0列,表示萼片的长度,[:0]就是所有行的第0个数据

y = v_iris.data[:, 1]

z = v_iris.data[:, 2]

zz = v_iris.data[:, 3]

species = v_iris.target

v_reuced = PCA(n_components=3).fit_transform(v_iris.data)

v_fig = plt.figure(figsize=[8, 8])

v_ax = Axes3D(v_fig)

# v_ax.set_title('鸢尾花降维分类',size=18)

v_ax.scatter(v_reuced[:, 0], v_reuced[:, 1], v_reuced[:, 2], c=species)

# v_ax.scatter(z, x, zz, c=species)

v_ax.set_xlabel('x')

v_ax.set_ylabel('y')

v_ax.set_zlabel('z')

# v_ax.xaxis.set_ticklabels(())

# v_ax.yaxis.set_ticklabels(())

# v_ax.zaxis.set_ticklabels(())

plt.savefig("iris_mplot3dpca4")

plt.show()

以上是 matplotlit绘制图像出现空白怎么解决? 的全部内容, 来源链接: utcz.com/p/938856.html

回到顶部