在matplotlib中创建曲面

2024-09-26 18:12:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着在三条线上创建曲面投掷。 每条线定义为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()

我得到了这个图像 my actual image

但我需要这样的图像: enter image description here


Tags: from图像import定义matplotlibasnpfig
1条回答
网友
1楼 · 发布于 2024-09-26 18:12:31

我的问题解决了。你知道吗

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()

enter image description here

相关问题 更多 >

    热门问题