How to use the cartopy.crs.Robinson function in Cartopy

To help you get started, we’ve selected a few Cartopy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bird-house / flyingpigeon / flyingpigeon / visualisation.py View on Github external
V = D.variables[variable]
            lon, lat = map(float, V.target_location.split(','))

        LOGGER.info('Lat and lon loaded')

    except Exception as e:
        msg = 'Failed to get data for plotting: {0}\n{1}'.format(ncfile, e)
        LOGGER.exception(msg)
        raise Exception(msg)

    try:
        fig = plt.figure(facecolor='w', edgecolor='k')
        fig.subplots_adjust(top=.95, bottom=.05, left=.03, right=.95)

        ax = plt.axes(
            projection=ccrs.Robinson(central_longitude=int(np.mean(lons))))

        divider = make_axes_locatable(ax)
        cax = divider.new_horizontal("4%", pad=0.15, axes_class=maxes.Axes)
        fig.add_axes(cax)

        ax.plot(lon, lat, marker='o', mfc='#292421', ms=13, transform=ccrs.PlateCarree())
        ax.plot(lon, lat, marker='o', mfc='#ffffff', ms=7, transform=ccrs.PlateCarree())

        cs = ax.contourf(lons, lats, var, 60,
                         transform=ccrs.PlateCarree(),
                         cmap=cmap, interpolation='nearest')

        ax.coastlines(color='k', linewidth=.8)
        ax.set_title(title)

        cb = plt.colorbar(cs, cax=cax, orientation='vertical')
github linsalrob / crAssphage / bin / map_drawing / drawing.py View on Github external
# there are three different alphas that we are looking at
    # the lines between samples (and potentially split those to the lines within and between continents)
    # the dots
    # the circles to themselves.

    # These are the maximum values
    #
    # Primer:     A       B      C
    # Cirlces:   530     485    289
    # Lines:      10       9     13
    # Dots:     2040    1806    680
    # at most out of these we only have 30 different numbers.

    # These numbers adjust the size of the things drawn
    ax = plt.axes(projection=ccrs.Robinson())

    # make the map global rather than have it zoom in to
    # the extents of any plotted data
    ax.set_global()
    # convert to a grayscale image. Uncomment stock_img to get color
    #ax.background_img(name='grayscale_shaded', resolution='low')
    ax.background_img(name='greyscale_ocean', resolution='low')

    #ax.stock_img()
    #ax.coastlines()

    # figure out our dots and lines
    t = time.time()
    dotdata, linedata = calculate_lines_dots(ll, dd, verbose=verbose)
    if verbose:
        sys.stderr.write(f"Calculating the lines took {time.time() - t} seconds\n")
github linsalrob / crAssphage / bin / map_drawing / pie_charts.py View on Github external
# there are three different alphas that we are looking at
    # the lines between samples (and potentially split those to the lines within and between continents)
    # the dots
    # the circles to themselves.

    # These are the maximum values
    #
    # Primer:     A       B      C
    # Cirlces:   530     485    289
    # Lines:      10       9     13
    # Dots:     2040    1806    680
    # at most out of these we only have 30 different numbers.

    # These numbers adjust the size of the things drawn
    ax = plt.axes(projection=ccrs.Robinson())

    # make the map global rather than have it zoom in to
    # the extents of any plotted data
    ax.set_global()
    # convert to a grayscale image. Uncomment stock_img to get color
    #ax.background_img(name='grayscale_shaded', resolution='low')
    #ax.background_img(name='PC_test', resolution='low') ## << OUR  FAVORITE
    ax.background_img(name='GreyScaleEarth', resolution='low')

    #ax.stock_img()
    #ax.coastlines()

    # figure out our dots and lines
    t = time.time()
    data = calculate_samediff(ll, dd, samekm=150, verbose=verbose)
    if verbose:
github linsalrob / EdwardsLab / cartopy / crAssphage_distance.py View on Github external
def plotmap(ll, dd, maxdist=1, maxlinewidth=3):
    """
    Plot the map of the dna distances and lat longs
    :param ll: The lon-lats
    :param dd: The distances to use
    :param maxdist: The maximum distance that we will scale to be maxlinewidth
    :return:
    """

    ax = plt.axes(projection=ccrs.Robinson())

    # make the map global rather than have it zoom in to
    # the extents of any plotted data
    ax.set_global()

    ax.stock_img()
    ax.coastlines()

    ## color the lines based on the maximum distance value
    jet = cm = plt.get_cmap('jet')
    cNorm = colors.Normalize(vmin=0, vmax=maxdist)
    scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=jet)

    # Using contourf to provide my colorbar info, then clearing the figure
    Z = [[0, 0], [0, 0]]
    levels = range(0, int(100 * maxdist) + 10, 10)
github SuperElastix / SimpleElastix / Utilities / Statistics / download_stats.py View on Github external
# Cartography plot of downloads by country
#
c_series = cbo_df.sum(axis=1)
c_series = c_series.sort_values(ascending=False)
cmap = mpl.cm.OrRd

max_dl = float(c_series.max())
min_dl = float(c_series.min())

norm = mpl.colors.LogNorm(vmin=min_dl, vmax=max_dl)
total_users = c_series.sum()
shapename = 'admin_0_countries'
countries_shp = shpreader.natural_earth(resolution='110m', category='cultural', name=shapename)

plt.figure(figsize=(14,8))
ax = plt.axes(projection=ccrs.Robinson() )
ax.add_feature(cf.BORDERS)
ax.add_feature(cf.COASTLINE)
#ax.add_feature(cf.OCEAN)
#ax.add_feature(cf.LAND)

hdl_dict = dict()

for country in shpreader.Reader(countries_shp).records():
    name = country.attributes['name_long']
    if name in c_series:
        num_users = c_series[name]
        hdl = ax.add_geometries(country.geometry, ccrs.PlateCarree(),
                               facecolor=cmap(norm(num_users),alpha=True))
        hdl_dict[name] = hdl

# Add ColorBar
github SciTools / cartopy / lib / cartopy / examples / logo.py View on Github external
def main():
    fig = plt.figure(figsize=[12, 6])
    ax = fig.add_subplot(1, 1, 1, projection=ccrs.Robinson())

    ax.coastlines()
    ax.gridlines()

    # generate a matplotlib path representing the word "cartopy"
    fp = FontProperties(family='Bitstream Vera Sans', weight='bold')
    logo_path = matplotlib.textpath.TextPath((-175, -35), 'cartopy',
                                             size=1, prop=fp)
    # scale the letters up to sensible longitude and latitude sizes
    logo_path._vertices *= np.array([80, 160])

    # add a background image
    im = ax.stock_img()
    # clip the image according to the logo_path. mpl v1.2.0 does not support
    # the transform API that cartopy makes use of, so we have to convert the
    # projection into a transform manually
github valentjn / vscode-ltex / tools / plotStats.py View on Github external
def plotMap():
  mapPath = os.path.join(repoDirPath, "_data", "stats", "map.json")
  with open(mapPath, "r") as f: map_ = json.load(f)

  fig = plt.figure(figsize=(14, 7))
  ax = fig.add_subplot(1, 1, 1, projection=cartopy.crs.Robinson())

  ax.set_global()
  ax.stock_img()
  ax.coastlines(alpha=0.3)
  ax.outline_patch.set_edgecolor("#0000004c")

  for child in ax.get_children():
    if isinstance(child, mpl.image.AxesImage): child.set_alpha(0.5)

  for stargazer in map_["stargazers"].values():
    if stargazer is None: continue
    ax.plot(stargazer["lon"], stargazer["lat"], ".", color="#8888ff", mec="#5555ff", ms=14,
        transform=cartopy.crs.PlateCarree())

  ax.set_facecolor("none")
  plt.savefig(os.path.join(repoDirPath, "images", "stats", "map.png"),
github bellockk / alphashape / examples / plot_geodataframe.py View on Github external
# Generate the alpha shape
alpha_shape = alphashape.alphashape(gdf)

# Initialize plot
ax = plt.axes(projection=ccrs.PlateCarree())

# Plot input points
gdf_proj = gdf.to_crs(ccrs.Robinson().proj4_init)
ax.scatter([p.x for p in gdf_proj['geometry']],
           [p.y for p in gdf_proj['geometry']],
           transform=ccrs.Robinson())

# Plot alpha shape
ax.add_geometries(
    alpha_shape.to_crs(ccrs.Robinson().proj4_init)['geometry'],
    crs=ccrs.Robinson(), alpha=.2)

plt.show()
github bradyrx / climpred / climpred / vis.py View on Github external
def make_cartopy(projection=ccrs.Robinson(), land_color='k',
                 grid_color='#D3D3D3', grid_lines=True, figsize=(12, 8),
                 frameon=True):
    """
    Returns a global cartopy projection with the defined projection style.

    Parameters
    ----------
    projection : ccrs projection instance (optional)
            Named map projection from Cartopy
    land_color : HEX or char string (optional)
            Color string to fill in continents with
    figsize : tuple (optional)
            Size of figure
    grid_color : HEX or char string (optional)
            Color string for the color of the grid lines
    grid_lines : boolean (optional)
github bird-house / flyingpigeon / flyingpigeon / visualisation.py View on Github external
:return graphic: graphic in specified format
    """
    import matplotlib.patches as mpatches
    lats, lons = utils.get_coordinates(resource, unrotate=True)

    # box_top = 45
    # x, y = [-20, -20, 45, 45, -44], [-45, box_top, box_top, -45, -45]

    xy = np.array([[np.min(lons), np.min(lats)],
                   [np.max(lons), np.min(lats)],
                   [np.max(lons), np.max(lats)],
                   [np.min(lons), np.max(lats)]])

    fig = plt.figure(figsize=(20, 10), dpi=600, facecolor='w', edgecolor='k')
    projection = ccrs.Robinson()
    #  ccrs.Orthographic(central_longitude=np.mean(xy[:, 0]),
    #  central_latitude=np.mean(xy[:, 1]),
    #  globe=None)  # Robinson()

    ax = plt.axes(projection=projection)
    ax.stock_img()
    ax.coastlines()
    ax.add_patch(mpatches.Polygon(xy, closed=True,  transform=ccrs.PlateCarree(), color='coral', alpha=0.6))
    # ccrs.Geodetic()
    ax.gridlines()
    plt.show()

    if file_extension is None:
        map_graphic = fig
    else:
        map_graphic = fig2plot(fig=fig, file_extension=file_extension)