你是对的。似乎2D绘图功能在3D绘图中没有等效项
fill_between。我建议的解决方案是将数据转换为3D多边形。这是相应的代码:
import math as mtimport matplotlib.pyplot as plimport numpy as npimport random as rdfrom mpl_toolkits.mplot3d import Axes3Dfrom mpl_toolkits.mplot3d.art3d import Poly3DCollection# Parameter (reference height)h = 0.0# Code to generate the datan = 200alpha = 0.75 * mt.pitheta = [alpha + 2.0 * mt.pi * (float(k) / float(n)) for k in range(0, n + 1)]xs = [1.0 * mt.cos(k) for k in theta]ys = [1.0 * mt.sin(k) for k in theta]zs = [abs(k - alpha - mt.pi) * rd.random() for k in theta]# Code to convert data in 3D polygonsv = []for k in range(0, len(xs) - 1): x = [xs[k], xs[k+1], xs[k+1], xs[k]] y = [ys[k], ys[k+1], ys[k+1], ys[k]] z = [zs[k], zs[k+1], h, h] #list is necessary in python 3/remove for python 2 v.append(list(zip(x, y, z))) poly3dCollection = Poly3DCollection(v)# Code to plot the 3D polygonsfig = pl.figure()ax = Axes3D(fig)ax.add_collection3d(poly3dCollection)ax.set_xlim([min(xs), max(xs)])ax.set_ylim([min(ys), max(ys)])ax.set_zlim([min(zs), max(zs)])ax.set_xlabel("x")ax.set_ylabel("y")ax.set_zlabel("z")pl.show()我希望这能帮到您。



