首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Python,两条曲线之间的曲面,matplotlib

Python,两条曲线之间的曲面,matplotlib
EN

Stack Overflow用户
提问于 2017-03-16 05:29:27
回答 1查看 826关注 0票数 0

我有两个numpy数组来表示3d空间中的一条线(注意

代码语言:javascript
运行
复制
# this represents line 1
x1 = [1,2,3]
y1 = [1,4,4]
z1 = [1,1,1]

# this represents line 2
x2 = [1,2,3,4]
y2 = [1,4,5,7]
z2 = [10,10,10]



# Notice that the array representing line 1 and the array representing line 2 have different sizes
# I am currently plotting the aforementioned '3D' lines as follows
ax.plot(x1,y1,z1)
ax.plot(x2,y2,z2)

我想在3D中绘制连接这些线的曲面,以获得如下所示:

https://pythonprogramming.net/static/images/dataviz/wire-frame-plane-tutorial-matplotlib-python-1024x682.png

我如何在python中使用matplotlib来做这件事?

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2017-03-16 16:20:26

您的点太少,无法创建一个合理的网格。

您所能做的就是使用plot_trisurf绘制点。

代码语言:javascript
运行
复制
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# this represents line 1
x1 = [1,2,3]
y1 = [1,4,4]
z1 = [1,1,1]

# this represents line 2
x2 = [1,2,3,4]
y2 = [1,4,5,7]
z2 = [10,10,10,10]

# Notice that the array representing line 1 and the array representing line 2 have different sizes
# I am currently plotting the aforementioned '3D' lines as follows
ax.plot(x1,y1,z1)
ax.plot(x2,y2,z2)

x=np.array([1,2,3, 1,2,3,4])
y=np.array([1,4,4, 1,4,5,7])
z=np.array([1,1,1, 10,10,10,10])

ax.plot_trisurf(x,y,z )

plt.show()

但结果并不是真正有吸引力。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42821036

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档