Skip to content

Instantly share code, notes, and snippets.

@weech
Created January 8, 2019 03:50
Show Gist options
  • Save weech/b2c836f644e66c319597cd8ca20e5bb9 to your computer and use it in GitHub Desktop.
Save weech/b2c836f644e66c319597cd8ca20e5bb9 to your computer and use it in GitHub Desktop.
Example of using Cartopy in Julia with PyPlot.jl
using PyCall
using PyPlot
@pyimport cartopy.crs as ccrs
plot_proj = ccrs.LambertCylindrical(central_longitude=180)
data_proj = ccrs.PlateCarree()
lons = collect([i for j in -90:90, i in -180:180]) # Important to collect before passing to PyPlot
lats = collect([j for j in -90:90, i in -180:180])
data = sin.((lons .+ lats) ./ 180 .* π)
ax0 = PyPlot.axes(projection=plot_proj) # Have to qualify with Module because of conflict with Base
ax0[:coastlines]() # Until PyCall drops 0.6 support will have to use this ugly syntax
pcolormesh(lons, lats, data, transform=data_proj)
# Real data will likely have to be transformed like pcolormesh(lons, lats, PyReverseDims(data), transform=data_proj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment