gpt4 book ai didi

python - matplotlib contourf3d plot_surface 与 trisurf

转载 作者:行者123 更新时间:2023-11-28 16:24:19 26 4
gpt4 key购买 nike

我正在尝试做 this和我的 data具有以下结构:

 0.90000000   0.90000000 -2133.80472139
0.90000000 0.95000000 -2133.84134433
...
1.87500000 1.82500000 -2133.96171262
1.87500000 1.87500000 -2133.95550450

使用下面的代码,我已经部分成功了。但是,我无法在 x-y、x-z 和 y-z 平面上绘制等高线。我不得不使用 plot_trisurf,因为 plot_surface 选项不适用于此数据(我真的不知道为什么)。创建 np.meshgrid 没有帮助(在将列表转换为 np.array 之后)。

import numpy as np
import sys
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm

filename = sys.argv[1]

with open(filename+'.dat', 'r') as f:
x = []
y = []
z = []
for line in f:
data = line.split()
x.append((float(data[0])))
y.append((float(data[1])))
z.append((float(data[2])))

zz = [627.503*(i+2134.070983645239) for i in z]

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_trisurf(x, y, zz, cmap=cm.jet, linewidth=0.1)
ax.dist=12
ax.view_init(30, 45)
ax.set_xlim(0.9, 1.9)
ax.set_ylim(0.9, 1.9)
ax.set_zlim(0, 170)
plt.show()

enter image description here

关于如何在 x-y 位置上绘制轮廓以及在 x-z 和 y-z 位置上进行投影,您有什么想法吗?

最佳答案

你必须使用三角形轮廓和填充三角形轮廓:tricontourtricontourf:http://matplotlib.org/examples/pylab_examples/tricontour_demo.html

我已经使用 tricontourf 向您添加了曲面到 XY 的投影图:

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_trisurf(x, y, zz, cmap=cm.jet, linewidth=0.1)
# projection of a surface to XY
ax.tricontourf(x, y, zz, zdir='z', offset=-1, cmap=cm.coolwarm)

ax.dist=12
ax.view_init(30, 45)
ax.set_xlim(0.9, 1.9)
ax.set_ylim(0.9, 1.9)
ax.set_zlim(0, 170)
plt.show()

enter image description here

关于python - matplotlib contourf3d plot_surface 与 trisurf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37793189/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com