简体   繁体   English

在matplotlib中创建曲面并线

[英]Creating surface in matplotlib throw on lines

I try to create curved surface throw on 3 lines. 我尝试在3条线上创建曲面投影。 Each line is defined in 3 points( each point have coordinate(x, y, z) ) 每条线定义为3个点(每个点具有坐标(x,y,z))

first line: (0, 0, 10) (0, 5, 5) (0, 10, 2) 第一行:(0,0,10)(0,5,5)(0,10,2)

second line: (2, 0, 10) (2, 5, 5) (2, 10, 2) 第二行:(2,0,10)(2,5,5)(2,10,2)

third line: (4, 1, 10) (4, 6, 5) (4, 11, 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()

I'm getting this image 我得到这张图片 我的实际形象

But I need image like this: 但是我需要这样的图像: 在此处输入图片说明

plot_trisurf is resolved my issue. 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()

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM