holtzy / The-Python-Graph-Gallery

A website displaying hundreds of charts made with Python
https://www.python-graph-gallery.com
BSD Zero Clause License
1.89k stars 372 forks source link

add post on how to change projections #471

Closed JosephBARBIERDARNAL closed 1 month ago

JosephBARBIERDARNAL commented 1 month ago

image made with

import matplotlib.pyplot as plt
import cartopy.crs as ccrs

# Define the projections
projections = [
   ccrs.Sinusoidal(),
   ccrs.PlateCarree(),
   ccrs.AzimuthalEquidistant(),
   ccrs.Mercator()
]

# Create a 2x2 grid of subplots with the specified projections
fig, axs = plt.subplots(ncols=2, nrows=2, figsize=(12, 8), 
                     subplot_kw={'projection': projections[0]})

# Flatten the axs array for easier iteration
axs = axs.flatten()

# Iterate over the axes and projections
for ax, proj in zip(axs, projections):
   ax.projection = proj
   ax.coastlines()
   ax.add_feature(cfeature.LAND, facecolor='#C0C0C0', edgecolor='none')
   ax.set_global()

plt.tight_layout()
plt.savefig('../../static/graph/projection_maps.png', bbox_inches='tight', dpi=300)
plt.show()