2014-09-03 37 views
1

正如標題已經說明我得到一個TypeError調用下面的方法時:餡餅()得到了一個意想不到的關鍵字參數「由startAngle」

plt.pie(ylist, labels=xlist, autopct='%1.1f%%', startangle=90, counterclock=False) 
>>> TypeError: pie() got an unexpected keyword argument 'startangle' 

當我離開了startangle我得到一個TypeErrorcounterclock

plt.pie(ylist, labels=xlist, autopct='%1.1f%%', counterclock=False) 
>>> TypeError: pie() got an unexpected keyword argument 'counterclock' 

當我也離開counterclock它工作正常,我得到所需的情節。

但是根據documentation這兩個關鍵字實際存在的,我也檢查了我的python-matplotlib庫的版本,以達到最新的(這是不可能的,該模塊matplotlib.pyplot是OUT- date matplotlib是最新的,是嗎?)。順便說一句,我使用Python 2.7.3。

有人可以解釋這個錯誤嗎?

+1

它是什麼版本,具體是什麼? – 2014-09-03 19:57:54

+0

使用'dpkg -s python-matplotlib | grep'Version'我得到輸出'Version:1.1.1〜rc1 + git20120423-0ubuntu1'。 – 2014-09-03 20:09:13

+1

1.1.1甚至沒有接近最新的。截至目前的最新版本是[1.4.0](http://matplotlib.org/contents.html)。 – 2014-09-03 20:12:04

回答

2

事實上matplotlib 1.1.x版本的didn't have that

def pie(x, explode=None, labels=None, colors=None, autopct=None, 
     pctdistance=0.6, shadow=False, labeldistance=1.1, hold=None): 

而版本1.4.0 does

def pie(x, explode=None, labels=None, colors=None, autopct=None, 
     pctdistance=0.6, shadow=False, labeldistance=1.1, startangle=None, 
     radius=None, counterclock=True, wedgeprops=None, textprops=None, 
     hold=None) 
2

我移動到一個新的安裝,Ubuntu的12.0後,今天上午有同樣的問題。 4

最後有效的是:

$pip uninstall matplotlib 
$apt-get remove --purge python-matplotlib 
$wget https://github.com/matplotlib/matplotlib/archive/master.zip 

解壓縮,cd到新目錄matplotlib主,

$python setup.py build 
$python setup.py install 

然後用PIP檢查:

$pip show matplotlib 
Name: matplotlib 
Version: 1.4.0 
Location: /usr/local/lib/python2.7/dist-packages 
Requires: numpy, six, python-dateutil, pyparsing, nose, mock, nose, mock 

成功!

相關問題