olb*_*en1 19 python matplotlib ipython-notebook
当我调用pyplot.title('some string')它时抛出异常,'str' object is not callable'.我从matplotlib在线文档中复制了以下内容:
mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)
# the histogram of the data
n, bins, patches = plt.hist(x, 50, normed=1, facecolor='g', alpha=0.75)
plt.xlabel('Smarts')
plt.ylabel('Probability')
plt.title('Histogram of IQ')
plt.text(60, .025, r'$\mu=100,\ \sigma=15$')
plt.axis([40, 160, 0, 0.03])
plt.grid(True)
plt.show()
Run Code Online (Sandbox Code Playgroud)
得到
TypeError Traceback (most recent call last)
<ipython-input-158-40fe7a831b06> in <module>()
8 plt.xlabel('Smarts')
9 plt.ylabel('Probability')
---> 10 plt.title('Histogram of IQ')
11 plt.text(60, .025, r'$\mu=100,\ \sigma=15$')
12 plt.axis([40, 160, 0, 0.03])
TypeError: 'str' object is not callable
Run Code Online (Sandbox Code Playgroud)
pyplot.suptitle() 工作正常
我在iMac上使用python 2.7.5和matplotlib的最新版本,带有I7处理器OSX 10.8和8 gig ram以及ipython笔记本.
有谁知道发生了什么?
ste*_*308 45
它发生在我身上,因为我试图plot.title = "Some string"重写这个title()方法.这就是它发生的确切原因:).正如其他人所说,你只需要重启内核,无需重新安装.
Fra*_*des 28
我有同样的问题.代码很好,但在解释器中,我之前使用了不正确的xlabel()调用.重新启动解释器(关闭并重新打开它)对我来说已经足够了,无需重新安装所有python/matplotlib!
cri*_*ari 11
尝试通过运行以下代码重新加载 matplotlib:
import matplotlib.pyplot as plt
from importlib import reload
plt=reload(plt)
Run Code Online (Sandbox Code Playgroud)
祝你好运