python - 错误绘图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()
它应该显示标题。我已删除并使用它的其他选项,但我仍然有我无法弄清楚的问题
解决方案
我还测试了你的代码,它运行没有任何问题。这可能是一个好的旧重启解决的问题,就像 Tianmin Lyu 说的那样。
此外,如果您最近更改了系统中的某些内容,之后此行为开始,可能会尝试恢复到您知道它有效的设置。
推荐阅读
- c - 运行 C 时 Visual Studio Code 中的错误输出
- python - 如何使用 Python 提取列表中的确定值?
- javascript - 如何在类的方法内的事件侦听器内使用“this”关键字而不会失去对类参数和方法参数的访问?
- java - 尝试为 Java 初学者获取帮助
- reactjs - 离子反应组件重复渲染
- javascript - 我的组件在通过数组传递道具时没有渲染
- python - Google Colab 在安装 pymatgen 时显示错误
- php - 如何使用 wp_mail() 发送 html 格式的消息?
- c# - 无法从另一个类更改 wpf c# 表单中的文本框
- c++ - 最小跳转次数(Segmentation Fault)