用python绘制双变量函数

用python绘制双变量函数,python,matplotlib,Python,Matplotlib,我必须画一个两变量函数来检查模型的简并度。我的代码如下所示: from numpy import exp,arange from pylab import meshgrid,cm,imshow,contour,clabel,colorbar,axis,title,show import math # the function that I'm going to plot def z_func(x1,x2): L = exp(-(1-x1)**2 - 100((x2-x1**2)**2))

我必须画一个两变量函数来检查模型的简并度。我的代码如下所示:

from numpy import exp,arange
from pylab import meshgrid,cm,imshow,contour,clabel,colorbar,axis,title,show
import math 


# the function that I'm going to plot
def z_func(x1,x2):
 L = exp(-(1-x1)**2 - 100((x2-x1**2)**2))
 return L

x1 = arange(-5.0,5.0,0.1)
x2 = arange(-5.0,5.0,0.1)
X1,X2 = meshgrid(x1, x2) # grid of point
Z = z_func(X1, X2) # evaluation of the function on the grid

im = imshow(Z,cmap=cm.RdBu) # drawing the function
# adding the Contour lines with labels
cset = contour(Z,arange(-1,1.5,0.2),linewidths=2,cmap=cm.Set2)
clabel(cset,inline=True,fmt='%1.1f',fontsize=10)
colorbar(im) # adding the colobar on the right
# latex fashion title
title('$z=exp(-(1-x1)^2 - 100(x2-x1^2)^2)$')
show()
我得到了以下错误:

File "multi.py", line 14, in <module>
    Z = z_func(X1, X2) # evaluation of the function on the grid
  File "multi.py", line 8, in z_func
    L = exp(-(1-x1)**2 - 100((x2-x1**2)**2))
TypeError: 'int' object is not callable
文件“multi.py”,第14行,在
Z=Z_func(X1,X2)#网格上函数的求值
文件“multi.py”,第8行,在z_func中
L=exp(-(1-x1)**2-100((x2-x1**2)**2))
TypeError:“int”对象不可调用

我认为如何定义我的函数,如何修复此错误并绘制函数存在问题?

100
是数字,因此不能像函数
100(…)
那样使用它。可能你忘了
*
,你需要
100*(…)
啊!谢谢,解决了问题
100
是数字,所以不能像函数
100(…)
那样使用它。可能你忘了
*
,你需要
100*(…)
啊!谢谢,问题解决了