【发布时间】:2020-05-25 22:10:51
【问题描述】:
x = np.linspace(0,5,11)
y = x ** 2
plt.plot(x,y)
plt.plot(x, y, 'r') # 'r' is the color red
plt.xlabel('X Axis Title Here') #Program stops here and prints str is not callable.
plt.ylabel('Y Axis Title Here')
plt.title('String Title Here')
我从源代码(来自在线课程的 Jupyter 笔记本)复制并粘贴了代码,但出现错误:str is not callable。为什么?
【问题讨论】:
-
似乎 xlabel 被设置为 Jupyter 笔记本中的字符串。你能检查整个笔记本,看看是否有任何地方 xlabel 被设置为字符串?另外,你在笔记本的任何地方有任何导入语句吗?如果有,是什么?
-
您提供的代码运行良好。
-
谢谢大家。阅读我的答案。出于某种未知原因,我关闭了笔记本,重新打开,运行程序,它运行了。在技术如此变化无常的情况下,人类如何能够向月球发射火箭并返回,我永远无法理解。
标签: python string jupyter-notebook