pie()得到一个意外的关键字参数'startangle'

时间:2014-09-03 19:36:55

标签: python matplotlib

由于标题已经表明我在调用以下方法时得到TypeError

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

当我遗漏startangle时,我TypeError获得了counterclock

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

当我也遗漏counterclock时,它工作正常,我得到了想要的情节。

然而根据documentation这两个关键字确实存在,我还检查了我的 python-matplotlib 库的版本是最新的(模块不可能) matplotlib.pyplot 已过时,而 matplotlib 是最新的,是吗?)。顺便说一句,我使用的是Python 2.7.3。

有人可以解释这个错误吗?

2 个答案:

答案 0 :(得分: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)

答案 1 :(得分: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-master,

$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

成功!