I have a problem with
matplotlib basemap plotting. I'm trying to plot a data array on a projection, and some coordinates are outside the projection:
import numpy as np
from mpl_toolkit.basemap import Basemap
m = Basemap(projection='ortho', lon_0=16, lat_0=56, lat_ts=0, resolution='c')
m.drawcoastlines()
lons = np.arange(0, 270)
lats = np.arange(-10, 10)
X, Y = np.meshgrid(lons, lats)
x, y = m()
m.pcolormesh(x, y, X)
If I use
m.pcolor
I don't have the problem, i.e. only those parts of the data which is on the projection are plotted:
But
pcolor
is
painfully slow on larger arrays (try increasing precision of lons and lats to .1 degrees).
pcolormesh()
can take a masked data array:
m.pcolormesh(x, y, np.ma.array(X, mask=x > 1e20))
but this only seems to affect the normalization of the colormap:
I think I have been able to get around this some time before, but I just can't find the solution anymore. Any ideas?