import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
mpl.rcParams['legend.fontsize'] = 10
fig = plt.figure()
ax = fig.gca(projection='3d')
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
z = np.linspace(-2, 2, 100)
r = z**2 + 1
x = r * np.sin(theta)
y = r * np.cos(theta)
ax.plot(x, y, z, label='parametric curve')
ax.legend()
plt.show()
可是ax.plot填入三个坐标参数的时候,需注意参数的类型。
开始的时候:ax.plot(x, y, z),x,y,z均为'numpy.ndarray'类型,在运行时候总是报错:ValueError: input operand has more dimensions than allowed by the axis remapping,百思不得其解