💻 源码
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# 设置随机种子保证可重复性
np.random.seed(42)

# 创建图形和3D坐标轴
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')

# 生成300个蓝色点(主要分布)
blue_points = np.random.normal(0, 1, (300, 3))
ax.scatter(blue_points[:,0], blue_points[:,1], blue_points[:,2],
           c='b', marker='o', alpha=0.6, label='common')

# 生成5个红色点(异常点/特殊点)
red_points = np.random.uniform(-3, 3, (5, 3))
ax.scatter(red_points[:,0], red_points[:,1], red_points[:,2],
           c='r', marker='^', s=100, label='special')

# 设置图表属性
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.set_title('dots in 3D space')
ax.legend()

plt.tight_layout()
plt.show()