Created
November 25, 2018 03:34
-
-
Save QuLogic/1bacb5f71afc2500bc83c0c8d546b289 to your computer and use it in GitHub Desktop.
Cartopy 0.17 tweets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import cartopy.crs as ccrs | |
################################################# | |
# New projections | |
for proj in [ccrs.EckertI, ccrs.EckertII, ccrs.EckertIII, ccrs.EckertIV, | |
ccrs.EckertV, ccrs.EckertVI, ccrs.EqualEarth, | |
ccrs.EquidistantConic]: | |
break | |
fig = plt.figure(figsize=(6, 3)) | |
ax = fig.add_axes([0.01, 0.01, 0.98, 0.92], projection=proj()) | |
ax.set_title(proj.__name__) | |
ax.stock_img() | |
ax.set_global() | |
fig.savefig(proj.__name__ + '.png') | |
################################################# | |
# New Stamen tiles | |
from cartopy.io.img_tiles import Stamen | |
fig = plt.figure(figsize=(6, 4.5)) | |
ax = fig.add_subplot(1, 1, 1, projection=ccrs.UTM(18)) | |
ax.set_extent([-79.6392727, -79.1132193, 43.5802533, 43.8554425], | |
crs=ccrs.PlateCarree()) | |
ax.add_image(Stamen('watercolor'), 12) | |
fig.savefig('Stamen.png') | |
################################################# | |
# Night shading example | |
import datetime | |
from matplotlib.animation import ArtistAnimation | |
from cartopy.feature.nightshade import Nightshade | |
fig = plt.figure(figsize=(10, 5)) | |
ax = fig.add_axes([0.01, 0.01, 0.98, 0.98], projection=ccrs.PlateCarree()) | |
ax.stock_img() | |
ax.set_global() | |
date = datetime.datetime(1999, 12, 31, 12) | |
artists = [] | |
for day in range(365): | |
# Each day shifts the inclination of the sun (latitude), and each minute | |
# shifts the time of day (longitude). | |
ns = Nightshade(date + datetime.timedelta(days=day, | |
minutes=24 * 60 / 365 * day), | |
alpha=0.2) | |
feat = ax.add_feature(ns) | |
sun = ax.scatter(180, 0, s=100, c='gold', zorder=10, transform=ns.crs) | |
artists.append([feat, sun]) | |
ani = ArtistAnimation(fig, artists, blit=True, interval=1000 / 24) | |
ani.save('nightshade.mp4', fps=24) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment