底图不显示绘制的数据(如果完全绘制)

时间:2018-06-29 18:23:11

标签: python-3.x matplotlib-basemap

我刚刚开始使用底图,但是遇到了问题。

当我跑步时:

import numpy as np
import matplotlib.pyplot as plt
import netCDF4 as nc
import glob
from mpl_toolkits.basemap import Basemap
import warnings #note that I did not include all of my code, so some imports may be unnecessary. 

%matplotlib inline
datapath = "/somedirectory/www.ncei.noaa.gov/data/avhrr-land-leaf-area-index-and-fapar/access/2001" #I've downloaded the data from here as well, I've averaged over every month.
datafiles = glob.glob(datapath+"/"+"avg_LAI_fAPAR*.nc")
data = [None]*len(datafiles)
month = [None]*len(datafiles)
lats = [None] * len(datafiles)
lons = [None] * len(datafiles)
fAPAR =[None] * len(datafiles)
LAI =[None] * len(datafiles)

for number, file in enumerate(datafiles):
    month[number] = file[-4:-2]
    data[number] = nc.Dataset(file,format = 'NETCDF4')
    lats[number] = data[number]["latitude"]
    lons[number] = data[number]["longitude"]
    fAPAR[number] = data[number]["FAPAR"]
    LAI[number] = data[number]["LAI"]


m = Basemap(width=5000000,height=3500000,
            resolution='l',\
            lat_ts=40)
for k in range(1): #only do one loop, it takes a long time to run on my machine. Idea is that is should be able to loop through all months in 2001
    print(k)
    plt.figure()#figsize=(20,10))
    lon, lat = np.meshgrid(lons[k], lats[k])
    xi, yi = m(lon,lat)
    cs = m.pcolor(xi,yi,np.squeeze(LAI[k][0])) #note that the first dimension [k] comes from the for-loop, the second [0] is the temporal part of the LAI (avereged out in a bash script). 

    m.drawcoastlines()
    m.drawcountries()

    cbar = m.colorbar(cs, location='bottom', pad="10%")
    plt.title('LAI on {}'.format(month[k]))`

该图显示为空,因此未绘制任何图(仅空白)。数据被屏蔽了,但是如果我取消屏蔽了数据(即用nan替换了屏蔽的数据),该图也不会显示任何内容。 np.nanmean(LAI[0])大约为1,但由于填充值为-90,所以常规均值大约为-100。 数据似乎可以在Linux中与NCview一起使用。

我使用安装了最新软件包的python 3.6工作。有人知道问题可能在哪里吗?

谢谢!

0 个答案:

没有答案