python画三维图

一、利用python画三维图

#三维绘图
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

fig1 = plt.figure()
ax = fig1.add_subplot(111, projection='3d')

x = out[out['target'] == (0)]
x=x.iloc[0:int(len(x)/400),:]
picture0=ax.scatter(x[0], x[1],x[2], c='blue', marker='o')

x = out[out['target'] == (1)]
x=x.iloc[0:int(len(x)/400),:]
picture1=ax.scatter(x[0], x[1],x[2], c='red', marker='x')


x = out[out['target'] == (2)]
x=x.iloc[0:int(len(x)/400),:]
picture2=ax.scatter(x[0], x[1],x[2], c='purple', marker='*')


x = out[out['target'] == (3)]
x=x.iloc[0:int(len(x)/400),:]
picture3=ax.scatter(x[0], x[1],x[2], c='gray', marker='s')


x = out[out['target'] == (4)]
x=x.iloc[0:int(len(x)/400),:]
picture4=ax.scatter(x[0], x[1],x[2], c='orange', marker='.')

# 设置坐标标签
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')

# 设置标题
plt.title("PCA Scatter Plot")

# 显示图形
plt.show()

python画三维图_第1张图片

你可能感兴趣的:(Python学习,机器学习)