我正在尝试使用plot_surface
and对小行星进行建模plot_wireframe
。我有小行星表面上的点的 xy 和 z 值。线框精确到小行星的形状,但表面图不适合线框。如何让曲面图适合线框,或者如何使用线框获得 3d 实体模型?这是我的模型代码:
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import cm
from matplotlib.mlab import griddata
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
data = np.genfromtxt('data.txt')
x = data[:,0]
y = data[:,1]
z = data[:,2]
ax.plot_wireframe(x, y, z, rstride=1, cstride=1, alpha=1)
xi = np.linspace(min(x), max(x))
yi = np.linspace(min(y), max(y))
X, Y = np.meshgrid(xi, yi)
Z = griddata(x, y, z, xi, yi)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
ax.set_zlim(-1.01, 1.01)
plt.show()
数据采用这种格式,尽管原始文件中有很多行:
-1.7738946051191869E-002 4.3461451610545973E-002 1.3393057231408241
-0.29733561550902488 0.32305812106837900 1.3393057231408241
-0.29733561550902488 0.16510132228266330 1.3548631099230350
-0.21872587865015569 2.4170900455101410E-002 1.3610011616437809
1.4452975249810950E-002 -0.20900795344486520 1.3610011616437809
1.5732454381265970E-002 -0.20900795344486520 1.3608751439485580
-0.34501536374240321 0.51320241386595655 1.3158820995876130
-0.40193014435941982 0.45628763324893978 1.3158820995876130
-0.42505849480150409 0.28183419537116011 1.3307863198123011
-0.18994178462386799 -0.19294290416565860 1.3424523041534830
1.4452975249810939E-002 -0.39733766403933751 1.3424523041534830
5.8021940902131752E-002 -0.57108837516584876 1.3210481842104100
9.3746267961881152E-002 -0.61017602710257668 1.3136798474111200
0.26609469681891229 -0.43782759824554562 1.3136798474111200
0.17938460413447810 0.39179924148155021 1.2357401964919650
8.9613011902522258E-002 0.42818009222325598 1.2584008460875080
0.33671539027096409 -0.47165177581327772 1.2965073126705291
0.53703772594296528 -0.47165177581327777 1.2357401964919561
-0.19242375014122229 0.71021685426700043 1.2584008460875080
-0.34501536374240321 0.66763766324752027 1.2904902860951690
希望你能帮忙