2016-10-12 25 views
0

我试图通过使numpy.meshgrid,转换的坐标映射x,y坐标使用底图(),然后使被施加pcolormesh绘制装箱数据的纵向条在地图上。代码是为Python 2.7:奇数行为与Python底图和pcolormesh

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() 

这给了一些非常奇怪的行为。通过改变什么区间上的数据是,在lon_0由底图()实例,或设置如何纬度/经度箱的定义,我们会得到不同的行为,如:

  • 没有纵向条
  • 1纵向条
  • 2纵向条(预期的行为)(如图:与lon_0 = -120制造)
  • '弥散' bin添加到地图的边缘(如图:与lon_0制成= 98)

我一直在试图解决这个问题耽搁一段时间;任何人都可以看到我做错了什么?

感谢您的阅读。

Correct output

Smear

回答