【发布时间】:2015-07-29 12:26:40
【问题描述】:
我是 python 的新手,使用 Matplotlib 绘制数据。我真的需要帮助,提前感谢您的回答。
所以,我有一个带有风数据 v 分量的 netCDF 文件。网格坐标:points=9600 (240x40)
lon : 0 to 358.5 by 1.5 degree_east circle
lat : 88.5 到 30 by -1.5 degree_north
我的代码是:
import numpy as np
import matplotlib
matplotlib.use('Agg')
from netCDF4 import Dataset
from matplotlib.mlab import griddata
from matplotlib import pyplot as plt
from mpl_toolkits.basemap import Basemap
#read data from NETcdf file ".nc"
my_file = '/home/Era-Interim/NH-EraInt-1979.nc'
fh = Dataset(my_file, mode='r')
lons = fh.variables['lon'][:]
lats = fh.variables['lat'][:]
V = fh.variables['V'][:]
V_units = fh.variables['V'].units
fh.close()
# create figure
fig = plt.figure(figsize=(20,20))
# create a map
m = Basemap(projection='nplaea',boundinglat=30,lon_0=10,resolution='l',round=True)
#draw parallels, meridians, coastlines, countries, mapboundary
m.drawcoastlines(linewidth=0.5)
m.drawcountries(linewidth=0.5)
#m.drawmapboundary(linewidth=2)
m.drawparallels(np.arange(30,90,20), labels=[1,1,0,0]) #paral in 10 degree, right, left
m.drawmeridians(np.arange(0,360,30), labels=[1,1,1,1]) #merid in 10 degree, bottom
#Plot the data on top of the map
lon,lat = np.meshgrid(lons,lats)
x,y = m(lon,lat)
cs = m.pcolor(x,y,np.squeeze(V),cmap=plt.cm.RdBu_r)
plt.title("", fontsize=25, verticalalignment='baseline')
plt.savefig("/home/Era-Interim/1.png")
结果我收到了一张地图(你可以在我的 dropbox 文件夹中找到)https://www.dropbox.com/sh/nvy8wcodk9jtat0/AAC-omkPP8_7uINSSXbzImeja?dl=0
在地图上,358.5 和 0 (360) lon 之间有白色像素,因为我没有 358.5 和 0 (360) lon 之间的数据。
问题是:我怎样才能改变网格的大小、重新网格化、插入数据或其他什么东西才能没有这个白色扇区?
【问题讨论】:
标签: python matplotlib