Home > database >  matplotlib legend TypeError: 'list' object is not callable [closed]
matplotlib legend TypeError: 'list' object is not callable [closed]

Time:09-22

I read the matplotlib documentation and still can't find a solution. I got the following error

> TypeError Traceback (most recent call last)
> TypeError: 'list' object is not callable```

with this code:

from matplotlib import pyplot as plt 

x = [1,2,3]
y = [3,2,1]
z = [10,6,4]
plt.plot(x,y)
plt.plot(x,z)
plt.legend(['this is y', 'this is z'])
plt.show()

full traceback:

TypeError Traceback (most recent call last)
<ipython-input-26-7e1351a04314> in <module>
  4 plt.plot(x,y)
  5 plt.plot(x,z)
----> 6 plt.legend(['this is y', 'this is z'])
  7 plt.show()

TypeError: 'list' object is not callable

CodePudding user response:

from matplotlib import pyplot as plt

x = [1, 2, 3]
y = [3, 2, 1]
z = [10, 6, 4]
plt.plot(x, y)
plt.plot(x, z)

plt.legend(['this is y', 'this is z'])
plt.show()

This piece of code is working fine without any error.

Another usage:

plt.plot(x, y, label = 'this is y')
plt.plot(x, z, label = 'this is z')

plt.legend()
plt.show()

Used: Python3.6 and matplotlib-3.1.2

  • Related