2017-05-08 66 views
0

我正在尝试使用matplotlib制作示例条形图。这是脚本:Matplotlib:示例将在终端上运行,但不会在调用脚本时运行

""" 
==================== 
Horizontal bar chart 
==================== 

This example showcases a simple horizontal bar chart. 
""" 
import matplotlib.pyplot as plt 
plt.rcdefaults() 
import numpy as np 
import matplotlib.pyplot as plt 


plt.rcdefaults() 
fig, ax = plt.subplots() 

# Example data 
people = ('Tom', 'Dick', 'Harry', 'Slim', 'Jim') 
y_pos = np.arange(len(people)) 
performance = 3 + 10 * np.random.rand(len(people)) 
error = np.random.rand(len(people)) 

ax.barh(y_pos, performance, xerr=error, align='center', 
     color='green', ecolor='black') 
ax.set_yticks(y_pos) 
ax.set_yticklabels(people) 
ax.invert_yaxis() # labels read top-to-bottom 
ax.set_xlabel('Performance') 
ax.set_title('How fast do you want to go today?') 

plt.show() 

当我直接的代码输入到它的工作原理,但是当我尝试调用脚本,我得到这个错误的终端:

Traceback (most recent call last): 
    File "bargraph.py", line 2, in <module> 
    import numpy as np 
    File "/Users/MattBell/Desktop/numpy.py", line 2, in <module> 
    import matplotlib.pyplot as plt 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/__init__.py", line 156, in <module> 
    from matplotlib.cbook import is_string_like 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/cbook.py", line 29, in <module> 
    import numpy.ma as ma 
ImportError: No module named ma 

我使用的OS X 10.10并运行python 2.7。

回答

2

你在桌面上有一个名为numpy.py的文件。删除或重命名它。

+0

谢谢。这解决了问题 –

相关问题