Odd behavior with python basemap and pcolormesh
<p>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:</p>

<pre><code>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()
</code></pre>

<p>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:</p>

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

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

<p>Thanks for reading.</p>

<p><a href="https://i.stack.imgur.com/bX0TH.png" rel="nofollow">Correct output</a></p>

<p><a href="https://i.stack.imgur.com/tvZMW.png" rel="nofollow">Smear</a></p>

<p>After some additional looking around I stumbled across this post: <a href="https://stackoverflow.com/questions/18186047/map-projection-and-forced-interpolation">Map projection and forced interpolation</a></p>

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

python numpy matplotlib matplotlib-basemap