我想画两条线,每条线分开时效果很好,但是当我一次画两条线时,就会出现错误:
回溯(最近一次调用):文件“2.py”,第 99 行,在 fspe2 = [fspe(t2,x) for t2 in t] TypeError: 'list' object is not callable
完整代码:
# -*- 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()
Run Code Online (Sandbox Code Playgroud)
回溯:从字面上看,一种让您跟踪从错误消息到导致错误消息的行的路径的方法。Python 的错误消息通常非常好,因此请从表面上看它所说的内容,然后再跟进。它甚至会描述产生这个结果的函数调用的路径,作为面包屑。
fspe2 = [fspe(t2,x) for t2 in t] TypeError: 'list' object is not callablefspe(t2,x).list。因此,fspe是list在这一点上。fspe分配的位置,在您的编辑器或 IDE(或在此浏览器窗口中)搜索该术语。def fspe(t,u): - 不,它定义了一个函数。fspe = [fspe(t1,x) for t1 in t]- 这是我们的罪魁祸首!您创建了一个list涉及先前定义的fspe函数,然后将其分配给相同的 name fspe,从而屏蔽该函数并使其无法访问(并且,如果没有更多现有引用,则由垃圾收集器完全删除)。fspe3orfspe_calcs或fspe_list。| 归档时间: |
|
| 查看次数: |
3284 次 |
| 最近记录: |