【发布时间】:2019-06-05 03:42:48
【问题描述】:
我是 试图创建一个带有标题的情节但得到这个错误我使用的是 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()
它应该显示标题。我已将其删除并使用其他选项,但我仍然无法解决问题
【问题讨论】:
-
用你的代码在我的电脑上运行良好。
-
这是你的全部代码吗?您能否检查是否有任何其他名为
plt的变量可能会被调用? -
print(plt)返回什么? -
它不返回任何东西
标签: python python-3.x