gpt4 book ai didi

python - 等高线图python中的长错误

转载 作者:太空宇宙 更新时间:2023-11-03 12:28:17 25 4
gpt4 key购买 nike

我正在尝试创建一个等高线图,其中 x 坐标标记为 EF,y 标记为 EB,z 是标记为 a 的函数。它返回下面发布的一个长错误。任何帮助,将不胜感激。错误是

File "contour.py", line 19, in <module>
c = plt.contour(EF,EB,a)
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2016, in contour
ret = ax.contour(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 7326, in contour
return mcontour.QuadContourSet(self, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/contour.py", line 1088, in __init__
ContourSet.__init__(self, ax, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/contour.py", line 686, in __init__
self._process_args(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/contour.py", line 1101, in _process_args
x, y, z = self._contour_args(args, kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/contour.py", line 1148, in _contour_args
x,y,z = self._check_xyz(args[:3], kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/contour.py", line 1180, in _check_xyz
raise TypeError("Input z must be a 2D array.")
TypeError: Input z must be a 2D array.

最佳答案

错误指出

TypeError: Input z must be a 2D array. 

如果您查看输入对象的大小:

print EF.shape, EB.shape, a.shape
(51,) (51,) (51,)

您会看到这些不是二维数组。您是否打算改用 XY

当我做出改变时

a = ((1+.5*(np.exp(1.7*X)+np.exp(1.7*Y)+np.exp(1.7*(X+Y))))/(1+np.exp(1.7*X)+np.exp(1.7*Y)+np.exp(1.7*(X+Y))))
c = plt.contour(EF,EB,a,30)

输出是

enter image description here

看起来您可能需要调整参数空间,因为所有有趣的东西都在 (0,0) 附近。

关于python - 等高线图python中的长错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18407307/

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