[Python] 纯文本查看 复制代码 import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# 定义坐标轴
fig = plt.figure()
ax1 = plt.axes(projection='3d')
# ax = fig.add_subplot(111,projection='3d') #这种方法也可以画多个子图
z = range(100)
x = range(100)
y = 5 * np.cos(z)
# zd = 13 * np.random.random(100)
# xd = 5 * np.sin(zd)
# yd = 5 * np.cos(zd)
cmp = plt.cm.get_cmap('rainbow')
# ax1.scatter3D(xd,yd,zd, cmap='rainbow') #绘制散点图
for i in range(len(x) - 1):
plt.plot([x[i], x[i + 1]], [y[i], y[i + 1]], linewidth=5, color=cmp(x[i] / max(x)))
#ax1.scatter3D(z, z, z, cmap='rainbow', color=cmp(x[i] / max(x))) # 绘制散点图
但是在绘制3D图时 却无法让颜色多样 (四维 就 第四维就是颜色) |