# 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.

pbrod / nvector / src / nvector / plot.py View on Github
``````(50, -20),
])
lats, lons = positions.T

# 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.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).')``````
SciTools / cartopy / lib / cartopy / examples / features.py View on Github
``````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())

plt.show()``````
Unidata / MetPy / v0.6 / _downloads / Station_Plot_with_Layout.py View on Github
``````# 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))
ax = fig.add_subplot(1, 1, 1, projection=proj)

# Add some various map elements to the plot to make it recognizable
ax.coastlines(resolution='110m', zorder=2, color='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`.``````
clcr / pyeo / pyeo / sen2map.py View on Github
``````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)

# overlay shapefile
# TODO change linewidth = 1
edgecolor='yellow', linewidth=2,
facecolor='none')

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)``````
clcr / pyeo / pyeo / Test_plotting_overlays.py View on Github
``````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.coastlines(resolution='10m', color='navy', linewidth=1)
ax1.gridlines()
BORDERS.scale = '10m'

# 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)``````
Unidata / MetPy / v0.6 / _downloads / Station_Plot.py View on Github
``````fig = plt.figure(figsize=(20, 10))
ax = fig.add_subplot(1, 1, 1, projection=proj)

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

# Add some various map elements to the plot to make it recognizable.
ax.coastlines(resolution='110m', zorder=2, color='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')``````
informatics-lab / forest / forest_lib / forest / geography.py View on Github
``````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))``````
kthyng / tracpy / tracpy / plotting.py View on Github
``````# 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.coastlines(resolution=res)  # coastline resolution options are '110m', '50m', '10m'
if plotstates:

# 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``````
noaa-oar-arl / MONET / scripts / sverify.py View on Github
``````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",
scale="50m",
facecolor="none",
)
return ax``````
Unidata / MetPy / examples / Four_Panel_Map.py View on Github
``````def plot_background(ax):
ax.set_extent([235., 290., 20., 55.])
return ax``````

## Cartopy

A Python library for cartographic visualizations with Matplotlib

BSD-3-Clause