我尝试在 3 条线上创建曲面。 每条线由 3 个点定义(每个点都有坐标(x, y, z))
第一行: (0, 0, 10) (0,5,5) (0, 10, 2)
第二行: (2, 0, 10) (2,5,5) (2, 10, 2)
第三行: (4、1、10) (4,6,5) (4,11,2)
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
x = [0, 2, 4, 0, 2, 4, 0, 2, 4]
y = [0, 0, 1, 5, 5, 6, 10, 10, 11]
z = [10, 10, 10, 5, 5, 5, 2, 2, 2]
X = x
Y = y
Z = z
Y, X = np.meshgrid(Y, X)
ax.plot_wireframe( X, Y, Z)
plt.show()
我得到了这张图片
但我需要这样的图像:
最佳答案
plot_trisurf 解决了我的问题。
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
x = [0, 2, 4, 0, 2, 4, 0, 2, 4]
y = [0, 0, 1, 5, 5, 6, 10, 10, 11]
z = [10, 10, 10, 5, 5, 5, 2, 2, 2]
X = x
Y = y
Z = z
ax.plot_trisurf( X, Y, Z)
plt.show()
关于python - 在 matplotlib 中创建曲面并抛出线条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28125000/