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