2017-10-12 53 views
1

座標列表我要繪製圖表使用的座標列表這樣的圖表:陰謀使用Python和多陣列錯誤

a = [<x1>, <y1>, <x2>, <y2>, …] 

那就是我用的算法:

import matplotlib.pyplot as plt 
import numpy as np 
a = [<x1>, <y1>, <x2>, <y2>, ….] 
x,y = np.array(a).reshape((len(a)/2, 2)).transpose() 
plt.plot(x,y) 

放我一個奇怪的錯誤失敗,根錯誤是:

ImportError: cannot import name multiarray 

所以這裏有什麼問題。我必須改變我的算法,或者有不同的方式來繪製使用座標列表的圖形。

謝謝;

,這是整個堆棧跟蹤:

/usr/bin/python3.3 /cs/usr/mohammadja/grph/graph.py 
Traceback (most recent call last): 
    File "/usr/lib/python3/dist-packages/numpy/core/__init__.py", line 16, in <module> 
    from . import multiarray 
ImportError: cannot import name multiarray 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "/cs/usr/mohammadja/grph/graph.py", line 1, in <module> 
    import matplotlib.pyplot as plt 
    File "/usr/lib/python3/dist-packages/matplotlib/__init__.py", line 122, in <module> 
    from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label 
    File "/usr/lib/python3/dist-packages/matplotlib/cbook.py", line 32, in <module> 
    import numpy as np 
    File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 142, in <module> 
    from . import add_newdocs 
    File "/usr/lib/python3/dist-packages/numpy/add_newdocs.py", line 13, in <module> 
    from numpy.lib import add_newdoc 
    File "/usr/lib/python3/dist-packages/numpy/lib/__init__.py", line 8, in <module> 
    from .type_check import * 
    File "/usr/lib/python3/dist-packages/numpy/lib/type_check.py", line 11, in <module> 
    import numpy.core.numeric as _nx 
    File "/usr/lib/python3/dist-packages/numpy/core/__init__.py", line 24, in <module> 
    raise ImportError(msg) 
ImportError: 
Importing the multiarray numpy extension module failed. Most 
likely you are trying to import a failed build of numpy. 
If you're working with a numpy git repo, try `git clean -xdf` (removes all 
files not under version control). Otherwise reinstall numpy. 


Process finished with exit code 1 
+0

可以粘貼整個堆棧跟蹤? –

+0

我過去了...... –

回答

1

不能破numpy的幫助,但這個工作清單上:

a = ['x1', 'y1', 'x2', 'y2', 'x3', 'y3'] 
x, y = a[::2], a[1::2] 

x 
Out[64]: ['x1', 'x2', 'x3'] 

y 
Out[65]: ['y1', 'y2', 'y3'] 

和切片索引是不可知的,適用於NP。陣列也

ar = np.array(a) 

x, y = ar[::2], ar[1::2] 

x 
Out[72]: 
array(['x1', 'x2', 'x3'], 
     dtype='<U2') 

y 
Out[73]: 
array(['y1', 'y2', 'y3'], 
     dtype='<U2') 

重新評論,你的意思是陰謀?

import matplotlib.pyplot as plt 
# import numpy as np # not used here but same code works with np.array too 


a = [*range(10)] 
x, y = x, y = a[::2], a[1::2] 
plt.plot(x, y) 
print(x, y) 
[0, 2, 4, 6, 8] [1, 3, 5, 7, 9] 

enter image description here

+0

好的......但我怎麼能打印x,y在這種情況下 –

+0

抱歉,但我有同樣的錯誤(ImportError:無法導入名稱multiarray) –