Raj*_*aj 1 python 3d plot matplotlib
我需要像这样在 3d 视图中绘制 2d 流线。正如帖子所建议的,我需要从 2d 图中提取流线和箭头,然后将其转换为 3d 数据。如何将此 2d 流线数据转换为 3d 数据并使用 mplot3d 进行绘图?
提前致谢
拉吉
编辑:@gg349,在您的帮助下,我可以在 3d 视图中绘制流线。剧情在这里
我有两个问题:
这个例子应该让你开始:
import matplotlib.pyplot as plt
import numpy as np
fig_tmp, ax_tmp = plt.subplots()
x, y = np.mgrid[0:2.5:1000j, -2.5:2.5:1000j]
vx, vy = np.cos(x - y), np.sin(x - y)
res = ax_tmp.streamplot(x.T, y.T, vx, vy, color='k')
fig_tmp.show()
# extract the lines from the temporary figure
lines = res.lines.get_paths()
#for l in lines:
# plot(l.vertices.T[0],l.vertices.T[1],'k')
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
for line in lines:
old_x = line.vertices.T[0]
old_y = line.vertices.T[1]
# apply for 2d to 3d transformation here
new_z = np.exp(-(old_x ** 2 + old_y ** 2) / 4)
new_x = 1.2 * old_x
new_y = 0.8 * old_y
ax.plot(new_x, new_y, new_z, 'k')
Run Code Online (Sandbox Code Playgroud)
这会生成一个中间临时数字:

从中提取线条。然后根据自己的喜好应用 2d 到 3d 点变换,并在新的 3d 图形中绘制相同的线:
| 归档时间: |
|
| 查看次数: |
3944 次 |
| 最近记录: |