2017-05-08 49 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

謝謝。這解決了問題 –

相關問題