Skip to content

Instantly share code, notes, and snippets.

@QuLogic
Created June 27, 2017 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save QuLogic/747ac39df0ddfe159b49f9e8c792eee6 to your computer and use it in GitHub Desktop.
Save QuLogic/747ac39df0ddfe159b49f9e8c792eee6 to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
from matplotlib.colors import Normalize
import numpy as np
import cartopy.crs as ccrs
import time
NROW = NCOL = 1
nlats, nlons = (241, 480)
lats = np.linspace(90, -90, nlats)
lons = np.linspace(0, 360, nlons)
l1, l2 = np.meshgrid(lons, lats)
data = l1 + l2
cmap = plt.get_cmap('viridis')
norm = Normalize(vmin=0, vmax=data.max())
start_time = time.time()
fig, axes = plt.subplots(NROW, NCOL,
subplot_kw=dict(projection=ccrs.Robinson(central_longitude=150)),
squeeze=False)
for ax in axes.flat:
coll = ax.pcolormesh(lons, lats, l1 + l2, transform=ccrs.PlateCarree(),
cmap=cmap, norm=norm)
ax.coastlines()
fig.savefig('pcolormesh_cartopy.png')
print("pcolormesh cartopy: {:.2f} s".format(time.time() - start_time))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment