Matplotlib pyplot.title(string)返回错误 [英] Matplotlib pyplot.title(string) returns error

查看:90
本文介绍了Matplotlib pyplot.title(string)返回错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我呼叫pyplot.title('some string')时,它将引发异常'str' object is not callable'. 我从matplotlib在线文档中复制了以下内容:

When I call pyplot.title('some string') it throws the exception, 'str' object is not callable'. I copied the following from the matplotlib online documentation:

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

并获得

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

pyplot.suptitle()正常工作

我在具有I7处理器OSX 10.8和8 gig ram以及ipython笔记本的iMac上使用python 2.7.5和最新版本的matplotlib.

I'm using python 2.7.5 and the latest release of matplotlib on an iMac with an I7 processor OSX 10.8 and 8 gig ram and ipython notebook.

有人知道发生了什么事吗?

Does anyone know what's going on?

推荐答案

发生在我身上的原因是我尝试执行plot.title = "Some string"以便重写title()方法.这就是它发生的确切原因:). 正如其他人所说,您只需要重新启动内核,而无需重新安装.

It happened to me because I tried to do plot.title = "Some string" so that rewrote the title() method. That's the exact reason why it happens :) . As others have said you just need to restart the kernel, no need to reinstall.

这篇关于Matplotlib pyplot.title(string)返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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