2013-10-18 3 views
10

Wenn ich pyplot.title('some string') aufrufen, löst es die Ausnahme 'str' object is not callable'. Ich kopierte die folgenden von der matplotlib Online-Dokumentation:Matplotlib pyplot.title (string) gibt Fehler

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

und bekommen

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

arbeitet Ich bin mit Python 2.7.5 und die neueste Version von matplotlib auf ein iMac mit einem I7-Prozessor OSX 10.8 und 8 Gig RAM und Ipython-Notebook.

Weiß jemand, was los ist?

+1

Es funktioniert für mich auf OSX 10.8.5 mit Python 2.7.5 und Matplotlib 1.3.0. Wie hast du ipython und matplotlib installiert? Ist der obige Code der einzige Code, den Sie hervorrufen? Führst du 'ipython notebook --pylab' oder wie initialisierst du es? –

+1

Ich kann das auch nicht reproduzieren. Hast du einen "plt.title = 'blah" irgendwo in deinem Code? – tacaswell

+0

Ich neu installiert Matplotlib (Pip uninstall dann pip installieren) und alles ist in Ordnung. Zuvor sagte mir plt.title, dass plt.title eine Saite sei. Jetzt bestätigt es, dass plt.title eine Funktion ist. Ich bin mir nicht sicher, ob ich alles herausbekommen habe, aber es funktioniert. Danke Leute. – olben1

Antwort

1

Hatte das gleiche Problem olben1, mit ipython, anaconda und dem --pylab Flag. Neuinstalliert und es hat funktioniert. Fwiw, mit einem Anaconda env macht die Deinstallation/Neuinstallation einfacher.

16

Ich hatte das gleiche Problem. Der Code war in Ordnung, aber im Interpreter hatte ich vorher falsche xlabel() -Aufrufe verwendet. Neustart des Interpreters (schließen und wieder öffnen) war genug für mich, keine Notwendigkeit, alle Python/Matplotlib neu zu installieren!

+0

Arbeitete wie ein Charme! – dasdachs

+0

Gleiches Problem - Ich arbeite in Jupyter und sobald ich den Kernel neu gestartet habe, war ich fertig. – nanselm2

11

Es ist mir passiert, weil ich versucht habe, plot.title = "Some string" zu tun, so dass die title() Methode umgeschrieben. Das ist der genaue Grund, warum es passiert :). Wie andere gesagt haben, müssen Sie nur den Kernel neu starten, keine Neuinstallation erforderlich.

+1

Dies sollte die akzeptierte Antwort hier sein ... Umschreiben der 'Titel' ist die Ursache für das Probem – Kickaha