Skip to content

Instantly share code, notes, and snippets.

@cpelley
cpelley / gist:6355283
Created August 27, 2013 15:45
Matplotlib colormap plotting (specified/all)
import numpy as np
import matplotlib.pyplot as plt
a = np.linspace(0, 1, 256).reshape(1,-1)
a = np.vstack((a,a))
plot_spec = None
if plot_spec is None:
# Get a list of the colormaps in matplotlib. Ignore the ones that end with
@cpelley
cpelley / gist:6351252
Created August 27, 2013 08:55
Calculating the grate circle distance from a point
"""
Calculating the grate circle distance from a point
==================================================
This example demonstrates how we might use an external library (pyproj) to
calculate the distance from our points in a cube to a specific location,
using our cubes grid mapping. We then associate this information
onto our original cube as an auxiliary coordinate, since this relates to the
original phenomena.
@cpelley
cpelley / gist:6351152
Created August 27, 2013 08:40
Plotting wind vectors (wind speed and direction)
import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import iris
from iris.coord_systems import GeogCS
from iris.cube import Cube
@cpelley
cpelley / gist:5781535
Last active December 18, 2015 12:18
Cartopy gridlines with labels on funky projections
import numpy as np
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
def workaround_gridlines(src_proj, labels=True):
# Workaround for plotting lines of constant latitude/longitude as gridlines
# labels not supported for this projection.
@cpelley
cpelley / iris masked regridding
Created August 29, 2012 13:41
Regridding a masked cube. The regridding method of a cube from iris
import numpy as np
import iris
def lat_lon_cube(x, mval, latgrid, longrid):
"""
Returns a masked cube with a latitude and longitude suitable for testing.
Args: