0
votes

I'm trying to plot longitudinal strips of binned data by making a numpy.meshgrid, converting the coordinates to map x,y coordinates using Basemap(), and then making a pcolormesh which is applied over the map. Code is for Python 2.7:

import numpy as np
from mpl_toolkits.basemap import Basemap, shiftgrid, addcyclic
import matplotlib.pyplot as plt

lon_tics =  np.linspace(0, 360.0, 60)
lat_tics = np.linspace(-90.0, 90.0, 30)
map_bins = np.zeros((60,30), dtype = np.int)
bin15 = np.random.randint(0,20,30) #we should see 2 strips
bin45 = np.random.randint(0,20,30) #but we get lots of strange results
map_bins[15] = bin15
map_bins[45] = bin45
m = Basemap(projection='moll',lon_0= -120,resolution='c') #NOTE changing lon_0 has weird results!
lon_bins_2d, lat_bins_2d = np.meshgrid(lon_tics, lat_tics)
xs, ys = m(lon_bins_2d, lat_bins_2d)
plt.pcolormesh(xs, ys, np.transpose(map_bins))
plt.colorbar()
m.drawparallels(np.arange(-90.,120.,30.), labels = [True])
m.drawmeridians(np.arange(0.,360.,60.), labels = [False])
plt.show()

This is giving some very weird behavior. By changing either what bins the data is in, where lon_0 is set by the Basemap() instantiation, or how the lat/lon bins are defined we will get differing behavior, such as:

  • No longitudinal strips
  • 1 longitudinal strips
  • 2 longitudinal strips (expected behavior) (pictured: made with lon_0=-120)
  • 'Smeared' bin to edge of map (pictured: made with lon_0=98)

I've been trying to resolve this issue for some time; can anyone see what I am doing wrong?

Thanks for reading.

Correct output

Smear

1

1 Answers

0
votes

After some additional looking around I stumbled across this post: Map projection and forced interpolation

This solved my problems for now, so I'm linking in case someone else runs into this issue.