Skip to content

Commit

Permalink
Example overlay plot (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaussion committed Oct 31, 2016
1 parent ddce727 commit 01d9938
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
50 changes: 50 additions & 0 deletions docs/examples/plot_wind_overlay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
"""
=============
Plot overlays
=============
Add contours and wind arrows to a salem plot
"""

import salem
import numpy as np
import matplotlib.pyplot as plt

# get the data at the latest time step
ds = salem.open_wrf_dataset(salem.get_demo_file('wrfout_d01.nc')).isel(time=-1)

# get the wind data at 10000 m a.s.l.
u = ds.salem.wrf_zlevel('U', 10000.)
v = ds.salem.wrf_zlevel('V', 10000.)
ws = ds.salem.wrf_zlevel('WS', 10000.)

# get the axes ready
f, ax = plt.subplots()

# plot the salem map background, make countries in grey
smap = ds.salem.get_map(countries=False)
smap.set_shapefile(countries=True, color='grey')
smap.plot(ax=ax)

# transform the coordinates to the map reference system and contour the data
xx, yy = smap.grid.transform(ws.west_east.values, ws.south_north.values,
crs=ws.salem.grid.proj)
cs = ax.contour(xx, yy, ws, cmap='viridis', levels=np.arange(0, 81, 10),
linewidths=2)

# Quiver only every 7th grid point
u = u[4::7, 4::7]
v = v[4::7, 4::7]

# transform their coordinates to the map reference system and plot the arrows
xx, yy = smap.grid.transform(u.west_east.values, u.south_north.values,
crs=u.salem.grid.proj)
xx, yy = np.meshgrid(xx, yy)
qu = ax.quiver(xx, yy, u.values, v.values)
qk = plt.quiverkey(qu, 0.7, 0.95, 50, '50 m s$^{-1}$',
labelpos='E', coordinates='figure')

# done!
plt.show()
2 changes: 2 additions & 0 deletions salem/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ def set_shapefile(self, shape=None, countries=False, oceans=False,
kwargs.setdefault('colors', (0.08984375, 0.65625, 0.8515625))
return self.set_shapefile(shapefiles['rivers'], **kwargs)
if countries:
kwargs.setdefault('zorder', 98)
return self.set_shapefile(shapefiles['world_borders'], **kwargs)

# Reset?
Expand Down Expand Up @@ -786,6 +787,7 @@ def set_lonlat_contours(self, interval=None, xinterval=None,
# Done
kwargs.setdefault('colors', 'gray')
kwargs.setdefault('linestyles', 'dashed')
kwargs.setdefault('zorder', 99)
self.ll_contour_kw = kwargs

def _shading_base(self, slope=None, relief_factor=0.7):
Expand Down

0 comments on commit 01d9938

Please sign in to comment.