Why do I get 'str' object is not callable?

Viewed 10238

I did this plot and it worked. The day after I ran it and I got this error:
TypeError: 'str' object is not callable.

plt.plot(A2, A15, color="black", label="TRC - P1", marker="o")
plt.xlabel("Amostras")
plt.ylabel("TRC (%)")
plt.title("TRC da P1")
plt.yticks([0, 10, 20, 30, 40, 50, 60, 70])
plt.xticks(rotation=60)

Following the error I have got enter image description here

4 Answers

I would guess that you defined somewhere in your notebook something like plt.xlabel = "something". This could also happened before you run this code shown. Try to close the Notebook and restart your Kernel. After restarting run your code shown and everything should be fine.

Guess you may have somewhere in the code used plt.xlabel = "Some Label" this will actually change the import of matplotlib.pyplot.

All we have to do here is simply reload the libraries by typing the following lines of code to fix the error without closing/restarting the notebook:

import matplotlib.pyplot as plt
from importlib import reload
plt=reload(plt)

If you are using visual studio code, and inside it Jupiter notebook. just Restart your kernel. then run again it will solve problem.

Yep it happens when you assigned these variables to something else. To fix it, just run:

del plt.xlabel
del plt.ylabel
import matplotlib.pyplot as plt
Related