我已经开始使用Basemap了,这似乎非常有用 .
如果我将纬度/经度网格上的一些全局数据绘制为填充轮廓,则效果很好:Iff我将lat_0和lon_0保留为零 . 一旦我改变了中心位置, Map 就会移动,但数据却没有 . 我很感激你的建议 .
我已经创建了一个我正在使用的代码的简单版本,其中包含一些简单的示例数据来说明问题 . 这些值在赤道处应该是大的,但在极点处应该很小 . 如果你使用lat_0和lon_0 = 0运行代码,它可以正常工作 . 但是,如果将中心位置更改为其他坐标,即使 Map 已移动,也会显示相同的图案/数据 .
from mpl_toolkits.basemap import Basemap, cm
import matplotlib.pyplot as plt
import numpy as np
# create data
lat = np.linspace(-90,90,num=180)
lon = np.linspace(-180,180,num=361)
h2o_north = np.linspace(1,65,num=90)
h2o_south = np.flipud(h2o_north)
h2o = np.append(h2o_north,h2o_south)
data = np.transpose(np.tile(h2o,(len(lon),1)))
# create figure and axes instances
fig = plt.figure(figsize=(10,10))
ax = fig.add_axes([0.1,0.1,0.8,0.8])
# create map
m = Basemap(projection='ortho',lon_0=-50,lat_0=50,resolution='l')
# draw coastlines and country boundaries
m.drawcoastlines()
m.drawcountries()
# draw parallels
parallels = np.arange(-90.,90,10.)
m.drawparallels(parallels)
# draw meridians
meridians = np.arange(180.,360.,10.)
m.drawmeridians(meridians)
ny = data.shape[0]
nx = data.shape[1]
lons, lats = m.makegrid(nx, ny) # get lat/lons of ny by nx evenly space grid
x, y = m(lons, lats) # compute map projection coordinates
# draw filled contours.
clevs = np.linspace(0,70,num=281)
cs = m.contourf(x,y,data,clevs,cmap=plt.cm.jet)
# colorbar
cbar = m.colorbar(cs,location='bottom',pad="5%",ticks=np.linspace(0,70,15))
cbar.set_label('Scale of the data')
plt.title('Some global data', fontsize=14)
1 回答
使用
np.meshgrid()
创建lon-lat的meshgrid,然后将其转换为投影坐标,数据就可以生成轮廓和绘图 .这是工作代码:
由此产生的情节: