# Using Basemap to plot points over a SST figure

Plotting a hydrographic cruise over the latest Sea Surface Temperature image available can help a lot with the planning and/or interpretation of the cruise data.

So first let's define a handy function to generate the such a map:

In [2]:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

def make_map(lonStart=-48, lonEnd=-32, latStart=-30, latEnd=-18, img=None):
m = Basemap(projection='merc', llcrnrlon=lonStart, urcrnrlon=lonEnd,
llcrnrlat=latStart, urcrnrlat=latEnd, resolution='c',
lat_ts=(latStart + latEnd) / 2.)

fig, ax = plt.subplots(figsize=(6, 6), facecolor='w')
m.ax = ax

m.imshow(image, origin='upper', alpha=0.75)

lonStart, latStart = -42, -26  # Crop the image.
lon_lim, lat_lim = m([lonStart, lonEnd], [latStart, latEnd])
m.ax.axis([lon_lim[0], lon_lim[1], lat_lim[0], lat_lim[1]])

dx = dy = 2
meridians = np.arange(lonStart, lonEnd + dy, dy)
parallels = np.arange(latStart,  latEnd + dx, dx)
xoffset = -lon_lim[0] + 1e4
yoffset = -lat_lim[0] + 1e4
kw = dict(linewidth=0)
m.drawparallels(parallels, xoffset=xoffset, labels=[1, 0, 0, 0], **kw)
m.drawmeridians(meridians, yoffset=yoffset, labels=[0, 0, 0, 1], **kw)
return fig, m

• Crop the image at known lon/lat corners.

Here is the result:

In [3]:
lon = [-40.77, -40.51, -40.30, -40.23, -40.13, -40.06, -39.99,
-39.87, -39.72, -39.52, -39.32, -39.11, -38.91, -38.71]
lat = [-21.29, -21.39, -21.48, -21.51, -21.56, -21.58, -21.62,
-21.69, -21.76, -21.86, -21.96, -22.08, -22.15, -22.25]

fig, m = make_map(img='./data/AVHRR.png')
kw = dict(marker='o', markerfacecolor='k', markeredgecolor='w', markersize=6, linestyle='none')
_ = m.plot(*m(lon, lat), **kw)

In [4]:
HTML(html)

Out[4]:

This post was written as an IPython notebook. It is available for download or as a static html.