我想在底图(这里是Lambert Conformal投影)上绘制模型的网格,以便代码从netCDF(.nc)文件中读取每个网格点的坐标(.nc文件仅包含这些坐标)然后用线条将它们矩形地(它是一个C网格)相互连接并绘制它们。到目前为止,我已使用“map.scatter”将这些坐标绘制为地图上的点;但是我的地图上只有点作为模型网格对我没有任何意义!
到目前为止,这是我编写的代码:
from mpl_toolkits.basemap import Basemap
from netCDF4 import Dataset as open_ncfile
import matplotlib.pyplot as plt
import matplotlib.lines as lines
import numpy as np
#-- open netcdf file
nc = open_ncfile('/desktop/grid.nc')
#-- read variable
lat = nc.variables['grid_corner_lat'][:]
lon = nc.variables['grid_corner_lon'][:]
#-- create figure and axes instances
fig = plt.figure(figsize=(15,15))
ax = fig.add_axes([0.1,0.1,0.8,0.9])
map = Basemap(llcrnrlon=-25,llcrnrlat=70,urcrnrlon=30,urcrnrlat=80,\
rsphere=(6378137.00,6356752.3142),\
resolution='l',area_thresh=1000.,projection='lcc',\
lat_0=85.,lat_1=75.,lon_0=0.,ax=ax)
map.drawcoastlines()
map.fillcontinents(color='0.90',lake_color='0.90')
# draw parallels and meridians.
map.drawparallels(np.arange(70.,90.,5.),labels=[1,1,0,1],fontsize=10)
map.drawmeridians(np.arange(-180.,180.,10.),labels=[1,1,0,1],fontsize=10)
map.drawmapboundary(fill_color='white')
x, y = map(lon,lat)
map.scatter(x,y,0.01,marker='.',color='k')
#-- add plot title
plt.show()
所以,我将不胜感激任何帮助或评论:)