Guest User

Untitled

a guest
May 23rd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. class Ui_MainWindow(QMainWindow, Ui_MainWindow):
  2.  
  3. def __init__(self, parent=None):
  4. super(Ui_MainWindow, self).__init__(parent)
  5. self.setupUi(self)
  6. self.btn_map_country.clicked.connect(self.map_country)
  7. self.graph2 = MyCanvas()
  8. self.gridLayout_3.addWidget(self.graph2, 0, 2, 1, 1)
  9.  
  10. def map_country(self):
  11. self.graph2.figure.clf()
  12. self.axes = self.graph2.figure.add_subplot(111)
  13.  
  14. map = Basemap(projection='cyl',lon_0=0,resolution='l')
  15. map.readshapefile('shape_test', 'state')
  16.  
  17. countries = ['Australia', 'Canada', 'France', 'Russia']
  18. patches = []
  19. patches2 = []
  20.  
  21. for info, shape in zip(map.state_info, map.state):
  22. if info['ADMIN'] in countries:
  23. patches.append( Polygon(np.array(shape), True) )
  24. else:
  25. patches2.append( Polygon(np.array(shape), True) )
  26.  
  27. self.axes.add_collection(PatchCollection(patches, facecolor= '#81F781', edgecolor='k', linewidths=0.5, zorder=2))
  28. self.axes.add_collection(PatchCollection(patches2, facecolor= '#DAD3D1', edgecolor='k', linewidths=0.5, zorder=2))
  29.  
  30. map.drawmapboundary(fill_color='#A9D0F5')
  31. self.graph2.draw()
  32.  
  33. class MyCanvas(FigureCanvas):
  34. def __init__(self, *args, **kwargs):
  35. self.figure = plt.figure()
  36. FigureCanvas.__init__(self, self.figure)
  37. self.figure.patch.set_facecolor("None")
  38. self.canvas = FigureCanvas(self.figure)
  39. toolbar = NavigationToolbar(self.canvas, self)
Add Comment
Please, Sign In to add comment