How to use the cartopy.feature.BORDERS 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 pbrod / nvector / src / nvector / plot.py View on Github external
(50, -20),
                          ])
    lats, lons = positions.T
    nvecs = lat_lon2n_E(rad(lats), rad(lons))

    # Find the horizontal mean position:
    n_EM_E = unit(np.sum(nvecs, axis=1).reshape((3, 1)))
    lat, lon = n_E2lat_lon(n_EM_E)
    lat, lon = deg(lat), deg(lon)
    print('Ex7, Average lat={0:2.1f}, lon={1:2.1f}'.format(lat[0], lon[0]))

    ax = plt.figure().gca(projection=ccrs.Orthographic(int(lon), int(lat)))
    ax.add_feature(cpf.OCEAN, zorder=0)
    ax.add_feature(cpf.LAND, zorder=0, edgecolor='black')
    ax.add_feature(cpf.COASTLINE)
    ax.add_feature(cpf.BORDERS, linestyle=':')
    ax.add_feature(cpf.LAKES, alpha=0.5)
    ax.add_feature(cpf.RIVERS)

    ax.set_global()
    ax.gridlines()

    # vector_crs = ccrs.Geodetic()
    vector_crs = ccrs.PlateCarree()

    ax.scatter(lon, lat, linewidth=5, marker='o', color='r',
               transform=vector_crs)
    ax.scatter(lons, lats, linewidth=5, marker='o', color='k',
               transform=vector_crs)

    plt.title('Figure of mean position (red dot) compared to \npositions '
              'A, B, and C (black dots).')
github SciTools / cartopy / lib / cartopy / examples / features.py View on Github external
def main():
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
    ax.set_extent([-20, 60, -40, 45], crs=ccrs.PlateCarree())

    ax.add_feature(cfeature.LAND)
    ax.add_feature(cfeature.OCEAN)
    ax.add_feature(cfeature.COASTLINE)
    ax.add_feature(cfeature.BORDERS, linestyle=':')
    ax.add_feature(cfeature.LAKES, alpha=0.5)
    ax.add_feature(cfeature.RIVERS)

    plt.show()
github Unidata / MetPy / v0.6 / _downloads / Station_Plot_with_Layout.py View on Github external
# Change the DPI of the resulting figure. Higher DPI drastically improves the
# look of the text rendering
plt.rcParams['savefig.dpi'] = 255

# Create the figure and an axes set to the projection
fig = plt.figure(figsize=(20, 10))
add_metpy_logo(fig, 1080, 290, size='large')
ax = fig.add_subplot(1, 1, 1, projection=proj)

# Add some various map elements to the plot to make it recognizable
ax.add_feature(feat.LAND, zorder=-1)
ax.add_feature(feat.OCEAN, zorder=-1)
ax.add_feature(feat.LAKES, zorder=-1)
ax.coastlines(resolution='110m', zorder=2, color='black')
ax.add_feature(state_boundaries, edgecolor='black')
ax.add_feature(feat.BORDERS, linewidth=2, edgecolor='black')

# Set plot bounds
ax.set_extent((-118, -73, 23, 50))

#
# Here's the actual station plot
#

# Start the station plot by specifying the axes to draw on, as well as the
# lon/lat of the stations (with transform). We also the fontsize to 12 pt.
stationplot = StationPlot(ax, data['longitude'], data['latitude'],
                          transform=ccrs.PlateCarree(), fontsize=12)

# The layout knows where everything should go, and things are standardized using
# the names of variables. So the layout pulls arrays out of `data` and plots them
# using `stationplot`.
github clcr / pyeo / pyeo / sen2map.py View on Github external
mapw = extll[1] - extll[0] # map width
    maph = extll[3] - extll[2] # map height

    left2 = extll[0] - mapw * margin
    right2 = extll[1] + mapw * margin
    bottom2 = extll[2] - maph * margin
    top2 = extll[3] + maph * margin
    extent2 = (left2, right2, bottom2, top2)

    ax2 = plt.axes(rect, projection=ccrs.PlateCarree(), )
    ax2.set_extent(extent2, crs=ccrs.PlateCarree())
    #  ax2.set_global()  will show the whole world as context

    ax2.coastlines(resolution='110m', color='grey', zorder=3.5)
    ax2.add_feature(cfeature.LAND, color='dimgrey', zorder=1.1)
    ax2.add_feature(cfeature.BORDERS, edgecolor='red', linestyle='-', zorder=3)
    ax2.add_feature(cfeature.OCEAN, zorder=2)

    # overlay shapefile
    # TODO change linewidth = 1
    shape_feature = ShapelyFeature(Reader(shapefile).geometries(), crs=shapeproj,
                                   edgecolor='yellow', linewidth=2,
                                   facecolor='none')
    ax2.add_feature(shape_feature, zorder=4)

    ax2.gridlines(zorder=3)

    # add location box of the main map
    box_x = [x0, x1, x1, x0, x0]
    box_y = [y0, y0, y1, y1, y0]
    plt.plot(box_x, box_y, color='black', transform=tifproj, linewidth=1, zorder=6)
github clcr / pyeo / pyeo / Test_plotting_overlays.py View on Github external
bottom2 = bottom1
top2 = bottom1 + 0.2 * (top1 - bottom1)

# now we overlay a new axes object on to the plot
# These are in unitless percentages of the figure size. (0,0 is bottom left)
left, bottom, width, height = [0.05, 0.3, 0.9, 0.6]
ax1 = fig.add_axes([left, bottom, width, height], projection=tifproj)
ax1.set_adjustable('box-forced')

# add coastlines etc.
ax1.coastlines(resolution='10m', color='navy', linewidth=1)
ax1.gridlines()
ax1.add_feature(cartopy.feature.LAKES, alpha=0.5)
ax1.add_feature(cartopy.feature.RIVERS)
BORDERS.scale = '10m'
ax1.add_feature(BORDERS, color='red')

# axes ticks
xticks = np.arange(left1, right1, 100000)
yticks = np.arange(bottom1, top1, 100000)
ax1.set_xticks(xticks, crs=tifproj)
ax1.set_yticks(yticks, crs=tifproj)
# stagger x gridline / tick labels
#labels = ax1.set_xticklabels(xticks)
#for i, label in enumerate(labels):
#    label.set_y(label.get_position()[1] - (i % 2) * 0.1)
# rotate the font orientation of the axis tick labels
plt.setp(ax1.get_xticklabels(), rotation=30, horizontalalignment='right')

# plot a line on the map
ax1.plot([left1 + 30000, left1 + 130000], [(top1 + bottom1) / 2, (top1 + bottom1) / 2],
         color='blue', linewidth=2, marker='.', zorder=90, transform=tifproj)
github Unidata / MetPy / v0.6 / _downloads / Station_Plot.py View on Github external
fig = plt.figure(figsize=(20, 10))
add_metpy_logo(fig, 1080, 290, size='large')
ax = fig.add_subplot(1, 1, 1, projection=proj)

# Set up a cartopy feature for state borders.
state_boundaries = feat.NaturalEarthFeature(category='cultural',
                                            name='admin_1_states_provinces_lines',
                                            scale='110m', facecolor='none')

# Add some various map elements to the plot to make it recognizable.
ax.add_feature(feat.LAND, zorder=-1)
ax.add_feature(feat.OCEAN, zorder=-1)
ax.add_feature(feat.LAKES, zorder=-1)
ax.coastlines(resolution='110m', zorder=2, color='black')
ax.add_feature(state_boundaries, edgecolor='black')
ax.add_feature(feat.BORDERS, linewidth=2, edgecolor='black')

# Set plot bounds
ax.set_extent((-118, -73, 23, 50))

#
# Here's the actual station plot
#

# Start the station plot by specifying the axes to draw on, as well as the
# lon/lat of the stations (with transform). We also the fontsize to 12 pt.
stationplot = StationPlot(ax, data['lon'].values, data['lat'].values, clip_on=True,
                          transform=ccrs.PlateCarree(), fontsize=12)

# Plot the temperature and dew point to the upper and lower left, respectively, of
# the center point. Each one uses a different color.
stationplot.plot_parameter('NW', data['air_temperature'], color='red')
github informatics-lab / forest / forest_lib / forest / geography.py View on Github external
def borders(extent, scale="50m"):
    """Add cartopy borders to a figure

    Translates cartopy.feature.BORDERS feature
    into collection of lines

    .. note:: This method assumes the map projection
              is cartopy.crs.PlateCarreee

    :param scale: cartopy scale '110m', '50m' or '10m'
    """
    feature = cartopy.feature.BORDERS
    feature.scale = scale
    return join(multi_lines(feature, extent))
github kthyng / tracpy / tracpy / plotting.py View on Github external
# the following two make the labels look like lat/lon format
    gl.xformatter = LONGITUDE_FORMATTER
    gl.yformatter = LATITUDE_FORMATTER
    gl.xlabels_bottom = False  # turn off labels where you don't want them
    gl.ylabels_right = False

    # plot isobaths
    ax.contour(grid.lon_rho, grid.lat_rho, grid.h, hlevs, colors='0.6',
               transform=pc, linewidths=0.5, alpha=halpha)

    # Do plot
    ax.add_feature(land, facecolor='0.8')
    ax.coastlines(resolution=res)  # coastline resolution options are '110m', '50m', '10m'
    if plotstates:
        ax.add_feature(states, edgecolor='0.2')
    ax.add_feature(cfeature.BORDERS, linestyle='-', edgecolor='0.2')

    # Outline numerical domain
    # if outline:  # backward compatibility
    #     outline = [1,1,1,1]
    if outline[0]:  # left
        ax.plot(grid.lon_rho[:, 0], grid.lat_rho[:, 0], 'k:', transform=pc)
    if outline[1]:  # right
        ax.plot(grid.lon_rho[:, -1], grid.lat_rho[:, -1], 'k:', transform=pc)
    if outline[2]:  # top
        ax.plot(grid.lon_rho[-1, :], grid.lat_rho[-1, :], 'k:', transform=pc)
    if outline[3]:  # bottom
        ax.plot(grid.lon_rho[0, :], grid.lat_rho[0, :], 'k:', transform=pc)

    return fig, ax
github noaa-oar-arl / MONET / scripts / sverify.py View on Github external
import cartopy.feature as cfeature

    fig = plt.figure(fignum)
    proj = ccrs.PlateCarree()
    ax = plt.axes(projection=proj)
    gl = ax.gridlines(draw_labels=True, linewidth=2, color="gray")
    gl.ylabels_right = False
    gl.xlabels_top = False
    states = cfeature.NaturalEarthFeature(
        category="cultural",
        name="admin_1_states_provinces_lines",
        scale="50m",
        facecolor="none",
    )
    ax.add_feature(states, edgecolor="gray")
    ax.add_feature(cfeature.BORDERS)
    ax.add_feature(cfeature.LAKES)
    ax.add_feature(cfeature.RIVERS)
    ax.add_feature(cfeature.COASTLINE)
    return ax
github Unidata / MetPy / examples / Four_Panel_Map.py View on Github external
def plot_background(ax):
    ax.set_extent([235., 290., 20., 55.])
    ax.add_feature(cfeature.COASTLINE.with_scale('50m'), linewidth=0.5)
    ax.add_feature(cfeature.STATES, linewidth=0.5)
    ax.add_feature(cfeature.BORDERS, linewidth=0.5)
    return ax