2、3D散点图
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
# 从mpl_toolkits.mplot3d导入Axes3D
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']
plt.rcParams['axes.unicode_minus'] = False
fig = plt.figure()
ax = Axes3D(fig)
# 定义3D坐标轴
x = np.random.normal(0, 1, 100)
y = np.random.normal(0, 1, 100)
z = np.random.normal(0, 1, 100)
# x, y, z 均为 0 到 1 之间的 100 个随机数
ax.scatter(x, y, z,color = 'r')
# 绘制3D散点图
ax.set_zlim(-2, 2)
# Z的范围
plt.title("3D散点图")
plt.show()