显示是模块:
import matplotlib
matplotlib.use('TkAgg') #TkAgg is quite slow but should work on all platforms.
import time
import numpy
import matplotlib.pyplot as plt
def display_2d_array(arr):
'''Display a square 2D numpy array as a greyscale image.'''
assert len(arr.shape) == 2 and arr.shape[0] == arr.shape[1]
plt.ion()
plt.clf()
plt.imshow(arr,origin="lower",extent=[0,arr.shape[0],0,arr.shape[0]])
plt.gray()
plt.draw()
raw_input('Hit enter to continue.')
但是当我在一个模块中调用它时,我得到了:
File "/Users/tomkimpson/display.py", line 8, in <module>
import matplotlib.pyplot as plt
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site packages/matplotlib/pyplot.py", line 26, in <module>
from matplotlib.figure import Figure, figaspect
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site- packages/matplotlib/figure.py", line 24, in <module>
import matplotlib.artist as martist
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.py", line 7, in <module>
from transforms import Bbox, IdentityTransform, TransformedBbox, \
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/transforms.py", line 35, in <module>
from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site- packages/matplotlib/_path.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site- packages/matplotlib/_path.so: no matching architecture in universal wrapper
任何人都知道这意味着什么?!
答案 0 :(得分:0)
看起来你正在OS X上运行它。看一下这个this question,其他OS X用户遇到了同样的错误。您的matplotlib安装可能已损坏。标记的答案与this page相关联,详细说明了如何在OS X上安装matplotlib。