matplotlib pcolor刻面不起作用

时间:2013-06-28 08:13:16

标签: python matplotlib

我尝试运行以下脚本(使用python 2.7):

import numpy as np
import matplotlib
print matplotlib.__version__

import matplotlib.pyplot as plt

plt.figure()
plt.pcolor(np.random.random((10,10)),shading="faceted")
plt.show()

并获得输出:

1.1.1rc2
Traceback (most recent call last):
  File "test.py", line 7, in <module>
    plt.pcolor(np.random.random((10,10)),shading="faceted")
  File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2413, in pcolor
    ret = ax.pcolor(*args, **kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 7044, in pcolor
    if 'antialiaseds' not in kwargs and ec.lower() == "none":
AttributeError: 'tuple' object has no attribute 'lower'

当我查看/usr/lib/pymodules/python2.7/matplotlib/axes.py时,我看到:

        if shading == 'faceted':
        edgecolors = 'k',
    else:
        edgecolors = 'none'
    if 'edgecolor' in kwargs:
        kwargs['edgecolors'] = kwargs.pop('edgecolor')
    ec = kwargs.setdefault('edgecolors', edgecolors)

    # aa setting will default via collections to patch.antialiased
    # unless the boundary is not stroked, in which case the
    # default will be False; with unstroked boundaries, aa
    # makes artifacts that are often disturbing.
    if 'antialiased' in kwargs:
        kwargs['antialiaseds'] = kwargs.pop('antialiased')
    if 'antialiaseds' not in kwargs and ec.lower() == "none":
            kwargs['antialiaseds'] = False

在edgecolors ='k'之后,问题似乎是“,”。因为像这样,edgecolors不是字符串而是元组....

我对matplolib的旧版本没有这个问题

1 个答案:

答案 0 :(得分:0)

使用Matplotlib 1.2.1您的日常工作适合我。 Axes.py中的matplotlib 1.2.1包含以下行,而不是axes.py版本中的行。

    if 'antialiaseds' not in kwargs and (is_string_like(ec) and
            ec.lower() == "none"):

我想你应该更新你的matplotlib安装。