onsdag 7 september 2011

Basemap plotting problem

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?

2 kommentarer:

  1. Hi, this seems like an old post, but I am coming across the same problem. Did you ever find a solution?

    SvaraRadera
  2. Wow, no I really can't remember. Haven't done any such work since 2011, sorry. If you do find the solution, perhaps you could add a note about it here, since at least you found this post when searching for a solution?

    SvaraRadera