繁体   English   中英

matplotlib pcolor多面无法正常工作

[英]matplotlib pcolor faceted not working

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

使用Matplotlib 1.2.1您的例程对我Matplotlib 1.2.1 matplotlib 1.2.1中的Axes.py包含以下几行,而不是您版本的axes.py

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

我想您应该更新matplotlib安装。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM