Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Ui_MainWindow(QMainWindow, Ui_MainWindow):
- def __init__(self, parent=None):
- super(Ui_MainWindow, self).__init__(parent)
- self.setupUi(self)
- self.btn_map_country.clicked.connect(self.map_country)
- self.graph2 = MyCanvas()
- self.gridLayout_3.addWidget(self.graph2, 0, 2, 1, 1)
- def map_country(self):
- self.graph2.figure.clf()
- self.axes = self.graph2.figure.add_subplot(111)
- map = Basemap(projection='cyl',lon_0=0,resolution='l')
- map.readshapefile('shape_test', 'state')
- countries = ['Australia', 'Canada', 'France', 'Russia']
- patches = []
- patches2 = []
- for info, shape in zip(map.state_info, map.state):
- if info['ADMIN'] in countries:
- patches.append( Polygon(np.array(shape), True) )
- else:
- patches2.append( Polygon(np.array(shape), True) )
- self.axes.add_collection(PatchCollection(patches, facecolor= '#81F781', edgecolor='k', linewidths=0.5, zorder=2))
- self.axes.add_collection(PatchCollection(patches2, facecolor= '#DAD3D1', edgecolor='k', linewidths=0.5, zorder=2))
- map.drawmapboundary(fill_color='#A9D0F5')
- self.graph2.draw()
- class MyCanvas(FigureCanvas):
- def __init__(self, *args, **kwargs):
- self.figure = plt.figure()
- FigureCanvas.__init__(self, self.figure)
- self.figure.patch.set_facecolor("None")
- self.canvas = FigureCanvas(self.figure)
- toolbar = NavigationToolbar(self.canvas, self)
Add Comment
Please, Sign In to add comment