【问题标题】:"TypeError: 'str' object is not callable" error while using Jupyter Notebook使用 Jupyter Notebook 时出现“TypeError:'str' object is not callable”错误
【发布时间】:2019-10-08 17:19:57
【问题描述】:

我尝试使用 matplotlib 中的 pyplot 绘制图表,一切正常,直到我尝试添加标题。

from matplotlib import pyplot as plt
a = [1, 4, 8]
b = [1, 9, 18]
plt.plot(a, b)
plt.title("Title")
plt.xlabel("x")
plt.ylabel("y")
plt.show()

除了标题,代码工作正常,显示错误如下:

        TypeError                                 Traceback (most recent call last)
    <ipython-input-25-a1c519e5c0a1> in <module>
          4 plt.xlabel("X")
          5 plt.ylabel("Y")
    ----> 6 plt.title("title")
          7 plt.show()

TypeError: 'str' object is not callable

顺便说一句,我正在使用 Jupyter notebook 运行它

【问题讨论】:

  • plot.show(c) 中的c 是什么?我想你不需要它。只需使用 plot.show()
  • 堆栈跟踪中的代码与您提供的代码不匹配。
  • 这段代码在我的 Jupyter notebook 中完美运行... python3

标签: python string jupyter-notebook anaconda callable


【解决方案1】:

我在 Jupyter 笔记本上两次遇到此错误。重新启动您的 anaconda 或更好:从内核选项卡重新启动并运行所有。这应该工作

【讨论】:

    【解决方案2】:

    重启你的内核。这是一个常见的错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-23
      • 2011-04-26
      • 1970-01-01
      • 2013-05-28
      • 2021-02-03
      • 2020-12-15
      • 2018-12-05
      相关资源
      最近更新 更多