簡體   English   中英

使用 Jupyter Notebook 時出現“TypeError: 'str' object is not callable”錯誤

[英]"TypeError: 'str' object is not callable" error while using Jupyter Notebook

我嘗試使用 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 運行它

重啟你的內核。 這是一個常見的錯誤。

我在 Jupyter 筆記本上兩次出現此錯誤。 重新啟動您的 anaconda 或更好:從內核選項卡重新啟動並運行所有。 這應該工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM