gpt4 book ai didi

python - 排列数据以制作 3d 曲面图

转载 作者:太空宇宙 更新时间:2023-11-04 00:37:56 27 4
gpt4 key购买 nike

我正在尝试制作 3D 表面图,但我无法将数据转换为正确的格式。

reshape 我的 Z 变量后得到:“ValueError:新数组的总大小必须保持不变”。 Z 的形状是 (2500,50)。 X 和 Y 的形状都是 (50,50)。我不确定为什么会这样。我的代码有什么明显的问题我遗漏了吗?

import numpy as np 
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt


def Mountain(F, P):
TA = ((TAmax-TAmin) * (((FF**g)/((FF**g)+FFhm**g)**a)/((((FF**g)/((FF**g)+FFhm**g))**a)+(SP/SPe)**a)))
return TA


F = np.linspace(0,120)
P = np.linspace(0,100)
Fb= int(21)
Fro= int(362)
FFhm = int(63)
g= int(3)
a = int(3)
SPmin = float(1.82)
SPbend = float(0.5)
SPe = int(10)
TAmax= int(1)
TAmin = int(0)

SP = SPmin + SPbend * np.log(1 + np.exp((P - SPmin)/SPbend))

FF= (Fb * (np.log(1 + np.exp(Fro/Fb)) - np.log(1 + np.exp((Fro-F)/Fb))))


fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
X, Y = np.meshgrid(F, P)
gh= list(zip(np.ravel(X), np.ravel(Y)))
zs = np.array(Mountain(F,P) for F,P in gh)
Z = zs.reshape(X.shape)

ax.plot_surface(X, Y, Z)

ax.set_xlabel('F')
ax.set_ylabel('P')
ax.set_zlabel('TA')

plt.show()

最佳答案

注意 zs 是空的。如果你想做列表理解,你应该使用括号(所以 np.array([Mountain(F,P) for F,P in gh])),虽然你真正想要的是 zs = np.array([Mountain(X[i],Y[i]) for i in range(X.shape[0])]) 而不是 ravel。

plot output

关于python - 排列数据以制作 3d 曲面图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43105631/

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