# Untitled

By: a guest on May 11th, 2012  |  syntax: None  |  size: 2.25 KB  |  hits: 27  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. connecting all numpy array plot points to each other using plt.plot() from matplotlib
2. plt.plot(*zip(*v.T)) #to plot all the points
3.      viewVX = (v[0]).T
4.      viewVY = (v[1]).T
5.      for i in range(0, 49):
6.         xPoints = viewVX[i], viewVX[i+1]
7.         print("xPoints is", xPoints)
8.         yPoints = viewVY[i+2], viewVY[i+3]
9.         print("yPoints is", yPoints)
10.         xy = xPoints, yPoints
11.         plt.plot(*zip(*xy), ls ='-')
12.
13. import matplotlib.pyplot as plt
14. import numpy as np
15. import itertools
16.
17. v=np.random.random((2,50))
18. plt.plot(
19.     *zip(*itertools.chain.from_iterable(itertools.combinations(v.T,2))),
20.     marker='o', markerfacecolor='red')
21. plt.show()
22.
23. In [4]: import numpy as np
24. In [5]: import itertools
25. In [7]: v=np.arange(8).reshape(2,4)
26. In [8]: v
27. Out[8]:
28. array([[0, 1, 2, 3],
29.        [4, 5, 6, 7]])
30.
31. In [10]: list(itertools.combinations(v.T,2))
32. Out[10]:
33. [(array([0, 4]), array([1, 5])),
34.  (array([0, 4]), array([2, 6])),
35.  (array([0, 4]), array([3, 7])),
36.  (array([1, 5]), array([2, 6])),
37.  (array([1, 5]), array([3, 7])),
38.  (array([2, 6]), array([3, 7]))]
39.
40. In [11]: list(itertools.chain.from_iterable(itertools.combinations(v.T,2)))
41. Out[11]:
42. [array([0, 4]),
43.  array([1, 5]),
44.  array([0, 4]),
45.  array([2, 6]),
46.  array([0, 4]),
47.  array([3, 7]),
48.  array([1, 5]),
49.  array([2, 6]),
50.  array([1, 5]),
51.  array([3, 7]),
52.  array([2, 6]),
53.  array([3, 7])]
54.
55. In [12]: zip(*itertools.chain.from_iterable(itertools.combinations(v.T,2)))
56. Out[12]: [(0, 1, 0, 2, 0, 3, 1, 2, 1, 3, 2, 3), (4, 5, 4, 6, 4, 7, 5, 6, 5, 7, 6, 7)]
57.
58. for i in range(0, 49):
59.     xPoints = viewVX[i], viewVX[i+1]
60.     print("xPoints is", xPoints)
61.     yPoints = viewVY[i+2], viewVY[i+3]
62.
63. def plot_complete(v):
64.      for x1, y1 in v.T:
65.           for x2, y2, in v.T:
66.              plt.plot([x1, x2], [y1, y2], 'b')
67.      plt.plot(v[0], v[1], 'sr')
68.
69. viewVX = (v[0]).T #this is if your matrix is 2x100 ie row [0] is x and row[1] is y
70.         viewVY = (v[1]).T
71.         for i in range(0, v.shape[1]): #v.shape[1] gives the number of columns
72.            for j in range(0, v.shape[1]):
73.               xPoints = viewVX[j], viewVX[i]
74.               yPoints = viewVY[j], viewVY[i]
75.               xy = [xPoints, yPoints]         #tuple/array of xx, yy point
76.               #print("xy points are", xy)
77.               plt.plot(xy[0],xy[1], ls ='-')