首页 > 解决方案 > 错误绘图str'对象不可调用python

问题描述

在此处输入图像描述

我正在尝试创建一个带有标题的情节,但出现此错误我正在使用 spyder 3.7

错误:

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

TypeError: 'str' object is not callable 

代码:

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()

它应该显示标题。我已删除并使用它的其他选项,但我仍然有我无法弄清楚的问题

标签: pythonpython-3.x

解决方案


我还测试了你的代码,它运行没有任何问题。这可能是一个好的旧重启解决的问题,就像 Tianmin Lyu 说的那样。

此外,如果您最近更改了系统中的某些内容,之后此行为开始,可能会尝试恢复到您知道它有效的设置。


推荐阅读