Advertisement
Guest User

Untitled

a guest
Nov 18th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. from matplotlib.patches import Ellipse, Circle
  3. import random
  4. r = lambda: random.randint(0,255)
  5.  
  6. def pCircle(point, rad, **kwargs):
  7. if "color" not in kwargs:
  8. return Ellipse(point,2*rad,2*rad)
  9. else:
  10. return Ellipse(point,2*rad,2*rad, color = kwargs["color"])
  11.  
  12. def drawCircles(circles, w, h, sub, hasColors):
  13. #print(circles)
  14. ax = plt.subplot(sub) # note we must use plt.subplots, not plt.subplot
  15. draw = []
  16. m = 0
  17. for x in circles:
  18. if hasColors:
  19. draw.append(pCircle((x[0],x[1]), 5, color = cluster_colors[x[2]]))
  20. else:
  21. draw.append(pCircle((x[0],x[1]), 5))
  22.  
  23. ax.set_aspect('equal')
  24. ax.axis([0,w,0,h])
  25. for y in draw:
  26. ax.add_artist(y)
  27. plt.draw()
  28.  
  29. def drawLines(lines):
  30. for x in lines:
  31. plt.plot([x[0][0], x[1][0]], [x[0][1], x[1][1]], 'k-')
  32.  
  33. f = open("../cplusplus/tests1000.txt","r");
  34. flines = open("../cplusplus/MST.txt","r");
  35. flines_start = open("../cplusplus/start.txt","r");
  36. fclasters = open("clasters.txt","r");
  37. fcluster_points = open("cluster_points.txt","r");
  38. circles = []
  39. start_lines = []
  40. lines = []
  41. clasters = []
  42. cluster_points = []
  43. cluster_colors = [0]*100000
  44. for x in (f.readlines())[1:]:
  45. nums = [float(n) for n in x.split()];
  46. circles.append((nums[0], nums[1]));
  47.  
  48. for x in (flines_start.readlines()):
  49. nums = [float(n) for n in x.split()];
  50. start_lines.append([[nums[0],nums[1]],[nums[2],nums[3]], nums[4]]);
  51.  
  52. for x in (flines.readlines()):
  53. nums = [float(n) for n in x.split()];
  54. lines.append([[nums[0],nums[1]],[nums[2],nums[3]], nums[4]]);
  55.  
  56. for x in (fclasters.readlines()):
  57. nums = [float(n) for n in x.split()];
  58. clasters.append([[nums[0],nums[1]],[nums[2],nums[3]], nums[4]]);
  59.  
  60. for x in (fcluster_points.readlines()):
  61. nums = [float(n) for n in x.split()];
  62. cluster_points.append([nums[0],nums[1], int(nums[2])]);
  63. cluster_colors[int(nums[2])] = '#%02X%02X%02X' % (r(),r(),r());
  64.  
  65. drawCircles(circles, 600,600,131, False)
  66. drawCircles(circles, 600,600,132, False)
  67. drawLines(lines)
  68. drawCircles(cluster_points, 600,600,133, True)
  69. drawLines(clasters)
  70. plt.show();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement