【发布时间】: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