0

我尝试运行以下脚本(使用 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 没有这个问题

4

1 回答 1

0

使用Matplotlib 1.2.1你的例行程序对我有用。Axes.pyinmatplotlib 1.2.1包含以下行,而不是您的axes.py.

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

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

于 2013-06-28T08:58:33.480 回答