“类型错误:‘str’对象不可调用";使用 Jupyter Notebook 时出错 [英] "TypeError: 'str' object is not callable" error while using Jupyter Notebook

查看:159
本文介绍了“类型错误:‘str’对象不可调用";使用 Jupyter Notebook 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I tried to plot a graph using pyplot from matplotlib and everything went fine until I tried to add the title.

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()

除标题外,代码运行正常,显示错误如下:

The code works fine except the title, from which an error is displayed as follows:

        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 运行它

BTW, I am running this using Jupyter notebook

推荐答案

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

I had this error twice on the Jupyter notebook. Restart your anaconda or better: from the kernel tab restart and run all. This should work

这篇关于“类型错误:‘str’对象不可调用";使用 Jupyter Notebook 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆