How to add colored background to Cartopy map

Want to get from this black and white map

Cartopy map in black and white without colored background

to this colored map

Cartopy map with colored background using stock_img

in just one line of code? Simply use cartopy’s stock_img():

how-to-add-colored-background-to-cartopy-map.py
ax.stock_img()

Complete example code

cartopy_colored_example.py
import cartopy.crs as ccrs
import cartopy.feature as cf
from matplotlib import pyplot as plt
ax = plt.axes(projection = ccrs.Mollweide())
ax.stock_img()
ax.add_feature(cf.COASTLINE)
ax.add_feature(cf.BORDERS)
# Make figure larger
plt.gcf().set_size_inches(20, 10)

# Save figure as SVG
plt.savefig("Cartopy-Colored.svg")

Cartopy map with colored background using stock_img


Check out similar posts by category: Cartopy, Geography, Python