I do Netcdf data processing using python on the spider with suplot. The data is monthly wind data information from Netcdf. I want to plot the data on a monthly basis. The problem is that the basemap can be plotted on all subplots, but the netcdf data cannot, only the last month appears (December).
With List code below
[from netCDF4 import Dataset as NetCDFFile
import matplotlib.pyplot as plt
import numpy as np
import os
import conda
from matplotlib import cm
conda_file_dir = conda.__file__
conda_dir = conda_file_dir.split('lib')[0]
proj_lib = os.path.join(os.path.join(conda_dir, 'share'), 'proj')
os.environ["PROJ_LIB"] = proj_lib
from mpl_toolkits.basemap import Basemap
nc = NetCDFFile('D:/GEE_QGIS/1982_UV_Monthly_0,25.nc')
lat = nc.variables['latitude'][:]
lon = nc.variables['longitude'][:]
time = nc.variables['time'][:]
u = nc.variables['u10'][:] # 10m u-component of winds
v = nc.variables['v10'][:] # 10m v-component of winds
map = Basemap(projection='merc',llcrnrlon=80.,llcrnrlat=-20.,urcrnrlon=180.,urcrnrlat=20.,resolution='i')
lons,lats= np.meshgrid(lon-180,lat) # for this dataset, longitude is 0 through 360, so you need to subtract 180 to properly display on map
x,y = map(lons,lats)
levels = [-10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10]
fig, axes = plt.subplots(nrows=4, ncols=3, figsize=(14,12))
rows = 4
columns = 3
month = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
for ax in axes.flat:
for i in month:
map = Basemap(projection='merc',llcrnrlon=80.,llcrnrlat=-20.,urcrnrlon=180.,urcrnrlat=20.,resolution='i',ax=ax)
map.drawcoastlines()
map.drawstates()
map.drawcountries()
map.drawlsmask(land_color='Linen', ocean_color='#CCFFFF') # can use HTML names or codes for colors
map.drawcounties() # you can even add counties (and other shapefiles!)
parallels = np.arange(-20,20,10.) # make latitude lines ever 5 degrees from 30N-50N
meridians = np.arange(80,180,10.) # make longitude lines every 5 degrees from 95W to 70W
map.drawparallels(parallels,labels=[1,0,0,0],fontsize=10)
map.drawmeridians(meridians,labels=[0,0,0,1],fontsize=10)
temp = map.contourf(x,y,u[i,:,:],levels=levels, extend='both', cmap=cm.RdBu, ax=ax)][1]
And data exmaple was
https://drive.google.com/file/d/175xau8iTaWkY3FTBH0CBQhz-dG8UocIw/view?usp=sharing
Result example
[Monthly Maps, but the plotted data was same time] 1