How to plot a circle on a cartopy map with python ?

Published: November 26, 2022

Tags: Python; Cartopy; Circle;

DMCA.com Protection Status

Examples of how to plot a circle on a cartopy map with python:

Plot a red circle using PlateCarree projection

To plot a circle on a cartopy map, a solution is to use matplotlib patches :

from matplotlib.pyplot import figure

import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import matplotlib.patches as mpatches

fig = figure(num=None, figsize=(12, 10), dpi=100, edgecolor='k')

map_proj = ccrs.PlateCarree()

ax = plt.axes(projection=map_proj)

ax.set_global()
ax.gridlines()

ax.coastlines(linewidth=0.5, color='k', resolution='110m')

poly = mpatches.Circle((2.52, 48.8), 12.5, color='r', transform=ccrs.PlateCarree())
ax.add_patch(poly)

plt.title('How to plot a circle on a map with cartopy ?')

plt.savefig("plot_circle_cartopy_PlateCarree.png", bbox_inches='tight', facecolor='white')

How to plot a circle on a cartopy map with python ?
How to plot a circle on a cartopy map with python ?

Plot a red circle using Robinson projection

With another cartopy projection

from matplotlib.pyplot import figure

import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import matplotlib.patches as mpatches

fig = figure(num=None, figsize=(12, 10), dpi=100, edgecolor='k')

map_proj = ccrs.Robinson()

ax = plt.axes(projection=map_proj)

ax.set_global()
ax.gridlines()

ax.coastlines(linewidth=0.5, color='k', resolution='110m')

poly = mpatches.Circle((2.52, 48.8), 12.5, color='r', transform=ccrs.PlateCarree())
ax.add_patch(poly)

plt.title('How to plot a circle on a map with cartopy ?')

plt.savefig("plot_circle_cartopy_Robinson.png", bbox_inches='tight', facecolor='white')

How to plot a circle on a cartopy map with python ?
How to plot a circle on a cartopy map with python ?

Image

of