def main(): blue = '#4b92db' # We're drawing a flag with a 3:5 aspect ratio. fig = plt.figure(figsize=[10, 6], facecolor=blue) # Put a blue background on the figure. blue_background = PathPatch(matplotlib.path.Path.unit_rectangle(), transform=fig.transFigure, color=blue, zorder=-1) fig.patches.append(blue_background) # Set up the Azimuthal Equidistant and Plate Carree projections # for later use. az_eq = ccrs.AzimuthalEquidistant(central_latitude=90) pc = ccrs.PlateCarree() # Pick a suitable location for the map (which is in an Azimuthal # Equidistant projection). ax = plt.axes([0.25, 0.24, 0.5, 0.54], projection=az_eq) # The background patch and outline patch are not needed in this example. ax.background_patch.set_facecolor('none') ax.outline_patch.set_edgecolor('none') # We want the map to go down to -60 degrees latitude. ax.set_extent([-180, 180, -60, 90], ccrs.PlateCarree()) # Importantly, we want the axes to be circular at the -60 latitude # rather than cartopy's default behaviour of zooming in and becoming # square. _, patch_radius = az_eq.transform_point(0, -60, pc) circular_path = matplotlib.path.Path.circle(0, patch_radius) ax.set_boundary(circular_path) if filled_land: ax.add_feature( cartopy.feature.LAND, facecolor='white', edgecolor='none') else: ax.stock_img() gl = ax.gridlines(crs=pc, linewidth=3, color='white', linestyle='-') # Meridians every 45 degrees, and 5 parallels. gl.xlocator = matplotlib.ticker.FixedLocator(np.arange(0, 361, 45)) parallels = np.linspace(-60, 70, 5, endpoint=True) gl.ylocator = matplotlib.ticker.FixedLocator(parallels) # Now add the olive branches around the axes. We do this in normalised # figure coordinates olive_leaf = olive_path() olives_bbox = Bbox.null() olives_bbox.update_from_path(olive_leaf) # The first olive branch goes from left to right. olive1_axes_bbox = Bbox([[0.45, 0.15], [0.725, 0.75]]) olive1_trans = BboxTransform(olives_bbox, olive1_axes_bbox) # THe second olive branch goes from right to left (mirroring the first). olive2_axes_bbox = Bbox([[0.55, 0.15], [0.275, 0.75]]) olive2_trans = BboxTransform(olives_bbox, olive2_axes_bbox) olive1 = PathPatch(olive_leaf, facecolor='white', edgecolor='none', transform=olive1_trans + fig.transFigure) olive2 = PathPatch(olive_leaf, facecolor='white', edgecolor='none', transform=olive2_trans + fig.transFigure) fig.patches.append(olive1) fig.patches.append(olive2) plt.show()
def main(): blue = '#4b92db' # We're drawing a flag with a 3:5 aspect ratio. fig = plt.figure(figsize=[7.5, 4.5], facecolor=blue) # Put a blue background on the figure. blue_background = PathPatch(matplotlib.path.Path.unit_rectangle(), transform=fig.transFigure, color=blue, zorder=-1) fig.patches.append(blue_background) # Set up the Azimuthal Equidistant and Plate Carree projections # for later use. az_eq = ccrs.AzimuthalEquidistant(central_latitude=90) pc = ccrs.PlateCarree() # Pick a suitable location for the map (which is in an Azimuthal # Equidistant projection). ax = fig.add_axes([0.25, 0.24, 0.5, 0.54], projection=az_eq) # The background patch is not needed in this example. ax.background_patch.set_facecolor('none') # The Axes frame produces the outer meridian line. for spine in ax.spines.values(): spine.update({'edgecolor': 'white', 'linewidth': 2}) # We want the map to go down to -60 degrees latitude. ax.set_extent([-180, 180, -60, 90], ccrs.PlateCarree()) # Importantly, we want the axes to be circular at the -60 latitude # rather than cartopy's default behaviour of zooming in and becoming # square. _, patch_radius = az_eq.transform_point(0, -60, pc) circular_path = matplotlib.path.Path.circle(0, patch_radius) ax.set_boundary(circular_path) if filled_land: ax.add_feature(cfeature.LAND, facecolor='white', edgecolor='none') else: ax.stock_img() gl = ax.gridlines(crs=pc, linewidth=2, color='white', linestyle='-') # Meridians every 45 degrees, and 4 parallels. gl.xlocator = matplotlib.ticker.FixedLocator(np.arange(-180, 181, 45)) parallels = np.arange(-30, 70, 30) gl.ylocator = matplotlib.ticker.FixedLocator(parallels) # Now add the olive branches around the axes. We do this in normalised # figure coordinates olive_leaf = olive_path() olives_bbox = Bbox.null() olives_bbox.update_from_path(olive_leaf) # The first olive branch goes from left to right. olive1_axes_bbox = Bbox([[0.45, 0.15], [0.725, 0.75]]) olive1_trans = BboxTransform(olives_bbox, olive1_axes_bbox) # THe second olive branch goes from right to left (mirroring the first). olive2_axes_bbox = Bbox([[0.55, 0.15], [0.275, 0.75]]) olive2_trans = BboxTransform(olives_bbox, olive2_axes_bbox) olive1 = PathPatch(olive_leaf, facecolor='white', edgecolor='none', transform=olive1_trans + fig.transFigure) olive2 = PathPatch(olive_leaf, facecolor='white', edgecolor='none', transform=olive2_trans + fig.transFigure) fig.patches.append(olive1) fig.patches.append(olive2) plt.show()
# We want the map to go down to -60 degrees latitude. ax.set_extent([-180, 180, -60, 90], ccrs.PlateCarree()) # Importantly, we want the axes to be circular at the -60 latitude # rather than cartopy's default behaviour of zooming in and becoming # square. _, patch_radius = az_eq.transform_point(0, -60, pc) circular_path = matplotlib.path.Path.circle(0, patch_radius) ax.set_boundary(circular_path) if filled_land: ax.add_feature(cfeature.LAND, facecolor='white', edgecolor='none') else: ax.stock_img() gl = ax.gridlines(crs=pc, linewidth=2, color='white', linestyle='-') # Meridians every 45 degrees, and 4 parallels. #gl.xlocator = matplotlib.ticker.FixedLocator(np.arange(-180, 181, 45)) #parallels = np.arange(-30, 70, 30) #gl.ylocator = matplotlib.ticker.FixedLocator(parallels) # Now add the olive branches around the axes. We do this in normalised # figure coordinates olive_leaf = olive_path() olives_bbox = Bbox.null() olives_bbox.update_from_path(olive_leaf) plt.show(block=False)