1

为了从以下数据生成 3D 表面,我应该在此处此处的任何示例中更改/添加什么?

[100, 0, 'TF', 0]
[100, 0, 'DF', 0]
[100, 50, 'TF', 0]
[100, 50, 'DF', 0]
[100, 100, 'TF', 0]
[100, 100, 'DF', 0]
[100, 150, 'TF', 0.84496124031007758]
[100, 150, 'DF', 0.87209302325581395]
[100, 200, 'TF', 0.88139534883720927]
[100, 200, 'DF', 0.86201550387596892]
[100, 250, 'TF', 0.87441860465116272]
[100, 250, 'DF', 0.889922480620155]
[100, 300, 'TF', 0.87984496124031009]
[100, 300, 'DF', 0.89922480620155043]
[100, 350, 'TF', 0.92015503875968996]
[100, 350, 'DF', 0.90697674418604657]

注意:我确实根据上面提到的代码尝试了一些事情,但到目前为止我还没有设法让它工作。我没有在这里引用我的代码的原因是因为我会让我的问题变得比实际更复杂。

4

2 回答 2

0

对 x 数据稍作改动会给你一个表面:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib
import numpy as np
from matplotlib import cm
from matplotlib import pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

data = [[100, 0, 'TF', 0],
        [100, 0, 'DF', 0],
        [100, 50, 'TF', 0],
        [100, 50, 'DF', 0],
        [100, 100, 'TF', 0],
        [100, 100, 'DF', 0],
        [100, 150, 'TF', 0.84496124031007758],
        [100, 150, 'DF', 0.87209302325581395],
        [100, 200, 'TF', 0.88139534883720927],
        [100, 200, 'DF', 0.86201550387596892],
        [100, 250, 'TF', 0.87441860465116272],
        [100, 250, 'DF', 0.889922480620155],
        [100, 300, 'TF', 0.87984496124031009],
        [100, 300, 'DF', 0.89922480620155043],
        [100, 350, 'TF', 0.92015503875968996],
        [100, 350, 'DF', 0.90697674418604657]
        ]
x = [item[0] for item in data]
# change x here
x = np.linspace(0, 100, num = 16)
y = [item[1] for item in data]
z = [item[3] for item in data]

X, Y = np.meshgrid(x, y)
_z, Z = np.meshgrid(x, z)

ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.YlGnBu_r)
ax.set_zlim3d(0, 1)
ax.set_xlabel(r'xlabel')
ax.set_ylabel(r'ylabel')
ax.set_zlabel(r'zlabel')
plt.show()
plt.close()

在此处输入图像描述

于 2013-10-09T00:39:11.620 回答
0

因此,您的数据并不是真正的 3D,因为所有 x 值都相同,但这是我编辑您发布的示例的方式。出于某种原因,X 想要成为列表列表。也许其他人知道为什么。在此处输入图像描述

from mpl_toolkits.mplot3d import Axes3D
import matplotlib
import numpy as np
from matplotlib import cm
from matplotlib import pyplot as plt

#step = 0.04
#maxval = 1.0
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# create supporting points in polar coordinates
#r = np.linspace(0,1.25,50)
#p = np.linspace(0,2*np.pi,50)
#R,P = np.meshgrid(r,p)
# transform them to cartesian system
#X,Y = R*np.cos(P),R*np.sin(P)

X=[]
for i in range(0,16):
    X.append([])
    X[i].append(100)
print(X)

Y=[]
for i in range(0,8):
    Y.append(50*i)
    Y.append(50*i)
print(Y)

Z=[]
Z.append(0)
Z.append(0)
Z.append(0)
Z.append(0)
Z.append(0)
Z.append(0)
Z.append(0.84496124031007758)
Z.append(0.87209302325581395)
Z.append(0.88139534883720927)
Z.append(0.86201550387596892)
Z.append(0.87441860465116272)
Z.append(0.889922480620155)
Z.append(0.87984496124031009)
Z.append(0.89922480620155043)
Z.append(0.92015503875968996)
Z.append(0.90697674418604657)
print(Z)


#Z = ((R**2 - 1)**2)
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.YlGnBu_r)
ax.set_zlim3d(0, 1)
ax.set_xlabel(r'xlabel')
ax.set_ylabel(r'ylabel')
ax.set_zlabel(r'zlabel')
plt.show()
于 2013-10-08T16:01:51.327 回答