2

enter image description here

I am trying to create a plot with titles but getting this error I am using spyder 3.7

Error:

   plt.title("Year vs Population in Bulgaria")

TypeError: 'str' object is not callable 

Code:

import matplotlib.pyplot as plt

years = [1983, 1984, 1985, 1986, 1987]
total_populations = [8939007, 8954518, 8960387, 8956741, 8943721]

plt.plot(years, total_populations)
plt.title("Year vs Population in Bulgaria")
plt.xlabel("Year")
plt.ylabel("Total Population")
plt.show()

It should show the title. I have removed and use it other options but I still have issues I cant figure out

4
  • 1
    It works well on my computer with your code. Commented Jun 5, 2019 at 3:49
  • 2
    Is this your entire code? Could you check if there are any other variables named plt that might be getting called instead? Commented Jun 5, 2019 at 3:51
  • 1
    What does print(plt) return? Commented Jun 5, 2019 at 3:52
  • it doesnt return anything Commented Jun 5, 2019 at 15:47

3 Answers 3

4

I also tested your code, and it ran without any issues. This might be a problem solved by a good old restart, like Tianmin Lyu said.

Also, in case you changed something in your system recently after which this behavior started, maybe try to revert back to that setup on which you know it worked.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for testing my code I havent changed anything I just did the installation and I keep getting that error maybe something is missing?
Persoanlly, I do not have any experience with Spyder. In case you haven’t already, can you try and run the script with ”python path/to/file.py” in a terminal?
2

plt.title="Your title" works fine

Instead of plt.title("Your title")

Comments

0

Yout code works fine on my Jupyter Notebook. And I've found a similar question, hope it works

Matplotlib pyplot.title(string) returns error

1 Comment

Even though this question has not been given a best answer, I think one piece of advice can be tried: restart the kernel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.