You can download this code by clicking the button below.
This code is now available for download.
This function generates a world map using the Cartopy library and adds features such as coastlines, borders, land, ocean, rivers, and lakes.
Technology Stack : Cartopy, Matplotlib
Code Type : The type of code
Code Difficulty : Advanced
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
def plot_world_map(projection=ccrs.PlateCarree(), extent=[-180, 180, -90, 90]):
"""
Generate a world map plot using Cartopy.
"""
fig, ax = plt.subplots(subplot_kw={'projection': projection})
ax.set_extent(extent)
ax.add_feature(cfeature.COASTLINE)
ax.add_feature(cfeature.BORDERS, linestyle=':')
ax.add_feature(cfeature.LAND)
ax.add_feature(cfeature.OCEAN)
ax.add_feature(cfeature.RIVERS)
ax.add_feature(cfeature.LAKES)
plt.show()