Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
意外的Python TypeError:“list”对象不可调用_Python_Matplotlib - Fatal编程技术网

意外的Python TypeError:“list”对象不可调用

意外的Python TypeError:“list”对象不可调用,python,matplotlib,Python,Matplotlib,我想画两条线,每一条线分开时都很好,但当我一次画两条线时,会出现一个错误: 回溯最近一次调用:文件2.py,第99行,在 fspe2=[fspet2,t中t2的x]类型错误:“list”对象不可调用 完整代码: # -*- coding: utf-8 -* import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl import math from pylab import * c = 2.998*10

我想画两条线,每一条线分开时都很好,但当我一次画两条线时,会出现一个错误:

回溯最近一次调用:文件2.py,第99行,在 fspe2=[fspet2,t中t2的x]类型错误:“list”对象不可调用

完整代码:

# -*- coding: utf-8 -*
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import math
from pylab import *

c = 2.998*10**10
hp = 6.626*10**-27
hb = 1.055*10**-27
kb = 1.381*10**-16
g = 6.673*10**-8
me = 9.109*10**-28
mp = 1.673*10**-24
q = 4.803*10**-10
sigT = 6.652*10**-25

p = 2.5
r014 = 1
E53 = 1
g42 = 1
delt12 =1
epsBR2 = 1
epseR1 = 1
DLG = 1 

r0 = r014*10**14
E0 = E53*10**53
g4 = g42*10**2.5
delt0 = delt12*10**12
epseR = epseR1*0.1
epsBR = epsBR2*0.01
n1 = 1.0
k = 0
DL = DLG*3.086*10**27

N0 = E0/(g4*mp*c**2)
SedL = (3*E0/(4*math.pi*n1*mp*c**2))**(1./3)
ttw = delt0/c  
ttn = SedL/(2*c*g4**(3./8))  
Reta = SedL/g4**(2./3)

def Gam3(t):
  if delt0 > SedL/(2*g4**(8./3)):
    return np.where(t<ttw,(SedL/delt0)**(3./8)*(4*t/ttw)**(-1./4),(SedL/delt0)**(3./8)*(4*ttw/ttw)**(-1./4)*(t/ttw)**(-7./16))
  else:
    return np.where(t<ttn,g4,g4*(t/ttn)**(-2./5))

def n3(t):
  if delt0 > SedL/(2*g4**(8./3)):
    return np.where(t<ttw,8*Gam3(t)**3*n1/g4,8*Gam3(ttw)**3*n1/g4*(t/ttw)**(-13./16))
  else:
    return np.where(t<ttn,7*n1*g4**2*(t/ttn)**-3,7*n1*g4**2*(t/ttn)**(-6./7))

def e3(t):
  if delt0 > SedL/(2*g4**(8./3)):
    return np.where(t<ttw,4*Gam3(t)**2*n1*mp*c**2,4*Gam3(ttw)**2*n1*mp*c**2*(t/ttw)**(-13./12))
  else:
    return np.where(t<ttn,4*g4**2*n1*mp*c**2,4*g4**2*n1*mp*c**2*(t/ttn)**(-8./7))

def Ne3(t):
  if delt0 > SedL/(2*g4**(8./3)):
    return np.where(t<ttw,N0*(t/ttw),N0)
  else:
    return np.where(t<ttn,N0*(t/ttn)**(3./2),N0)

gem = lambda t : epseR*e3(t)/(n3(t)*me*c**2)*(p-2)/(p-1)
BR  = lambda t : np.sqrt(8*math.pi*epsBR*e3(t))
gec = lambda t : 6*math.pi*me*c/(sigT*BR(t)**2*Gam3(t)*t)
num = lambda t : 3*q*BR(t)/(4*math.pi*me*c)*gem(t)**2*Gam3(t)
nuc = lambda t : 3*q*BR(t)/(4*math.pi*me*c)*gec(t)**2*Gam3(t)
Fmax = lambda t : Ne3(t)*math.sqrt(3)*q**3*BR(t)/(me*c**2)*Gam3(t)/(4*math.pi*DL**2)

def fspe(t,u):
  if num(t)<nuc(t):
    return np.where(u<num(t),(u/num(t))**(1./3)*Fmax(t),np.where(u<nuc(t),(u/num(t))**(-(p-1.)/2)*Fmax(t),(u/nuc(t))**(-p/2)*(nuc(t)/num(t))**(-(p-1.)/2)*Fmax(t)))*u
  else:
    return np.where(u<nuc(t),(u/muc(t))**(1./3)*Fmax(t),np.where(u<num(t),(u/nuc(t))**(-1./2)*Fmax(t),(u/num(t))**(-p/2)*(num(t)/nuc(t))**(-1.2)*Fmax(t)))*u

xmin = 2
xmax = 10
i = np.arange(xmin,xmax,0.01)
t = 10**i

plt.figure('God Bless: Lightcure')
plt.title(r'Lightcurve''\n2 Cases')
plt.xlabel(r'log t')
plt.ylabel(r'log Flux')

x = 10**10
fspe = [fspe(t1,x) for t1 in t] 
Lightcurve1 = [math.log10(a5) for a5 in fspe]
plt.plot(i,Lightcurve1,'.',label=r'$\nu=10^{10}$')

########################
## Strange thing happens!The above 4 sentences work well,
## why added the same statements, there's an Error?
x = 10**15
fspe2 = [fspe(t2,x) for t2 in t] 
### This place feedback--Traceback (most recent call last):
#  File "1.py", line 94, in <module>
#    fspe2 = [fspe(t2,x) for t2 in t] 
#TypeError: 'list' object is not callable
Lightcurve2 = [math.log10(a6) for a6 in fspe2]
plt.plot(i,Lightcurve2,'>',label=r'$\nu=10^{15}$')
#######################

plt.legend()
plt.grid(True)
plt.show()  

您可以通过第91行的列表在函数fspe上赋值

fspe = [fspe(t1,x) for t1 in t]
我做了一个简单的改变

fspe_list = [fspe(t1,x) for t1 in t] 
Lightcurve1 = [math.log10(a5) for a5 in fspe_list]

这至少是正常的。我不知道它是否符合您的要求。

回溯:从字面上说,是一种将错误消息的路径追溯到导致错误的行的方法。Python的错误消息通常是非常好的,所以从字面上理解它所说的内容,然后再返回。它甚至会描述产生这个结果的函数调用的路径,这些函数调用充当面包屑

fspe2=[fspet2,t中t2的x]类型错误:“list”对象不可调用 你叫什么来着?该行中唯一的实例是fspet2,x。 它想叫什么?名单。因此,fspe在这一点上是一个列表。 让我们找出fspe的分配位置,在编辑器或IDE中或在此浏览器窗口中搜索该术语。 def fspet,u:-不,它定义了一个函数。 fspe=[fspet1,t中t1的x]-这是我们的罪犯!您创建了一个包含先前定义的fspe函数的列表,然后将其分配给同名fspe,从而屏蔽该函数并使其不可访问,如果没有对它的现有引用,则由垃圾收集器完全删除。 解决方法是给它一个唯一的名称,比如fspe3或fspe_calcs或fspe_list。
同时给出完整的错误tracebackjesuslove@jesuslove-220s系列:~/matplotlib$python 2.py回溯最近的调用last:File 2.py,第99行,在fspe2=[fspet2,x代表t中的t2]类型错误:“list”对象不可调用jesuslove@jesuslove-220s系列:~/matplotlib$fspe=[fspet1,x代表t中的t1]第91行使用列表在函数上赋值。你如何纠正取决于你想做什么。非常感谢你,上帝保佑我的朋友!哇,你解释得很好!我从中学到了很多!非常感谢你,上帝保佑我的朋友!