TypeError: object of type 'int' has no len()
TypeError: object of type 'int' has no len()
我已经尝试了很多方法来解决这个问题,但我找不到这个错误的答案:
TypeError: object of type 'int' has no len()
这是我的代码:
def CalculaDeltaT(Tn, Tm, Fr, T, P):
return (Tn * Fr * T) - (P * T) - (Tm * T)
deltaT = CalculaDeltaT
def CalculaDeltaR(Rn, Fv, Rm, Mt, R):
return (Rn * Fv * R) - (Rm * Mt * R)
deltaR = CalculaDeltaR
def CalculaDeltaV(Vn, Vm, Mr, V):
return (Vn * V) - (Vm * Mr * V)
deltaV = CalculaDeltaV
import matplotlib.pyplot as plt
tmax = 10
Tp = [0] * tmax
Tn = 0.2
Fr = 0.6
Tm = 0.3
P = 0.1
T = [0] * tmax
T[0] = 10
Rn = 0.4
Fv = 0.6
Rm = 0.1
Mt = 0.2
R = [0] * tmax
R[0] = 10
Vn = 0.5
Vm = 0.8
Mr = 0.8
V = [0] * tmax
V[0] = 10
print(len(V))
print(len(R))
print(len(T))
print(len(Tp))
for i in range (1, tmax):
T[i] = T[i-1] + deltaT(Tn, Fr, Tm, T[i-1], P)
Tp[i] = i
plt.plot(Tp, T)
plt.axis(0, 10, 10, 1000)
plt.ylabel('T[Tubarões]')
plt.xlabel('Tempo[em anos]')
plt.title(r'T em função de Tempo')
plt.show()
我试过调试,但找不到问题所在。我是一名学生,所以如果这是一个基本问题,我很抱歉。
您收到此错误:
Traceback (most recent call last):
File "/home/PycharmProjects/experiments.py", line 8, in <module>
plt.axis(0, 10, 0, 100)
File "/home/python3/lib/python3.4/site-packages/matplotlib/pyplot.py", line 1417, in axis
v = ax.axis(*v, **kwargs)
File "/home/python3/lib/python3.4/site-packages/matplotlib/axes/_base.py", line 1337, in axis
if len(v) != 4:
TypeError: object of type 'int' has no len()
axis(v)
文档:
....
sets the min and max of the x and y axes, with
v = [xmin, xmax, ymin, ymax]
....if len(*v)==0
, you can pass in xmin, xmax, ymin, ymax
as kwargs selectively to alter just those limits without changing
the others.
您应该使用 plt.axis([0, 10, 0, 10])
或 plt.axis(xmin=0, xmax=10, ymin=0, ymax=10)
。
(我还调整了 ymin
和 ymax
以显示您当前的数据,因为 y
得到的值小于您设置的限制)
结果:
我已经尝试了很多方法来解决这个问题,但我找不到这个错误的答案:
TypeError: object of type 'int' has no len()
这是我的代码:
def CalculaDeltaT(Tn, Tm, Fr, T, P):
return (Tn * Fr * T) - (P * T) - (Tm * T)
deltaT = CalculaDeltaT
def CalculaDeltaR(Rn, Fv, Rm, Mt, R):
return (Rn * Fv * R) - (Rm * Mt * R)
deltaR = CalculaDeltaR
def CalculaDeltaV(Vn, Vm, Mr, V):
return (Vn * V) - (Vm * Mr * V)
deltaV = CalculaDeltaV
import matplotlib.pyplot as plt
tmax = 10
Tp = [0] * tmax
Tn = 0.2
Fr = 0.6
Tm = 0.3
P = 0.1
T = [0] * tmax
T[0] = 10
Rn = 0.4
Fv = 0.6
Rm = 0.1
Mt = 0.2
R = [0] * tmax
R[0] = 10
Vn = 0.5
Vm = 0.8
Mr = 0.8
V = [0] * tmax
V[0] = 10
print(len(V))
print(len(R))
print(len(T))
print(len(Tp))
for i in range (1, tmax):
T[i] = T[i-1] + deltaT(Tn, Fr, Tm, T[i-1], P)
Tp[i] = i
plt.plot(Tp, T)
plt.axis(0, 10, 10, 1000)
plt.ylabel('T[Tubarões]')
plt.xlabel('Tempo[em anos]')
plt.title(r'T em função de Tempo')
plt.show()
我试过调试,但找不到问题所在。我是一名学生,所以如果这是一个基本问题,我很抱歉。
您收到此错误:
Traceback (most recent call last):
File "/home/PycharmProjects/experiments.py", line 8, in <module>
plt.axis(0, 10, 0, 100)
File "/home/python3/lib/python3.4/site-packages/matplotlib/pyplot.py", line 1417, in axis
v = ax.axis(*v, **kwargs)
File "/home/python3/lib/python3.4/site-packages/matplotlib/axes/_base.py", line 1337, in axis
if len(v) != 4:
TypeError: object of type 'int' has no len()
axis(v)
文档:
.... sets the min and max of the x and y axes, with v = [xmin, xmax, ymin, ymax]
....if
len(*v)==0
, you can pass in xmin, xmax, ymin, ymax as kwargs selectively to alter just those limits without changing the others.
您应该使用 plt.axis([0, 10, 0, 10])
或 plt.axis(xmin=0, xmax=10, ymin=0, ymax=10)
。
(我还调整了 ymin
和 ymax
以显示您当前的数据,因为 y
得到的值小于您设置的限制)
结果: