def zoom_map(self, buffer=0.2, lonmin=None, lonmax=None, latmin=None, latmax=None): self.logger.info('Zooming basemap to (%s to %s E), (%s to %s N)' % (lonmin, lonmax, latmin, latmax) ) map = Basemap(lonmin, latmin, lonmax, latmax, resolution=None, projection='merc') # Find Basemap offset between new and old maps xo, yo = map(lonmin, latmin, inverse=False) xoo, yoo = self.map(lonmin, latmin, inverse=False) xoff = xoo-xo yoff = yoo-yo # Copy polygons and adjust for offsets map.coastpolygons = [ (tuple(np.subtract(pol[0], xoff)), tuple(np.subtract(pol[1], yoff))) for pol in self.map.coastpolygons] coastsegs_new = [] for c in self.map.coastsegs: xc, yc = list(zip(*c)) newxc = tuple(xce - xoff for xce in xc) newyc = tuple(yce - yoff for yce in yc) coastsegs_new.append(list(zip(newxc, newyc))) map.coastsegs = coastsegs_new map.coastpolygontypes = map_orig.coastpolygontypes map.resolution = map_orig.resolution self.map = map