python - TypeError: object of type 'int' has no len() -
i've tried lot of ways solve problem can't find answer error:
typeerror: object of type 'int' has no len()
here code:
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 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)) in range (1, tmax): t[i] = t[i-1] + deltat(tn, fr, tm, t[i-1], p) tp[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()
i've tried debugging couldn't find problem was. student sorry if basic question.
you getting error:
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)
documentation:
.... sets min , max of x , y axes, v = [xmin, xmax, ymin, ymax]
....if
len(*v)==0
, can pass in xmin, xmax, ymin, ymax kwargs selectively alter limits without changing others.
you should either use plt.axis([0, 10, 0, 10])
or plt.axis(xmin=0, xmax=10, ymin=0, ymax=10)
.
(i adjusted ymin
, ymax
show current data, since y
gets smaller values limits set)
result:
Comments
Post a Comment