I am trying to plot a climate variable (wind) using a netCDF file on mpl_toolkits.basemap. I was following the code presented in https://www.aosc.umd.edu/~cmartin/python/examples/netcdf_example1.html. When I try to overlay latitude and longitude on my basemap, it just returns a grid rather than a basemap overlaid with latitude and longitude lines. What can be the problem?
The code is as follows:
`
from netCDF4 import Dataset as ds
import matplotlib.pyplot as plt
import numpy as np
import plotly
from mpl_toolkits.basemap import Basemap
file = ds("spdmax_MM5I_ccsm_2038010106.nc")
lat = file.variables['lat'][:]
lon = file.variables['lon'][:]
time = file.variables['time'][:]
wind = file.variables['spdmax'][:]
parallels = np.arange(15.0,55.0,5.0)
meridians = np.arange(-145.0,-105.0,5.0)
map.drawparallels(parallels,labels=[1,0,0,0],fontsize=10)
map.drawmeridians(meridians,labels=[0,0,0,1],fontsize=10)
'
Please also see the attached screenshot which has detailed pictures of our problem!
Hello,
I am trying to plot a climate variable (wind) using a netCDF file on mpl_toolkits.basemap. I was following the code presented in https://www.aosc.umd.edu/~cmartin/python/examples/netcdf_example1.html. When I try to overlay latitude and longitude on my basemap, it just returns a grid rather than a basemap overlaid with latitude and longitude lines. What can be the problem?
The code is as follows: ` from netCDF4 import Dataset as ds import matplotlib.pyplot as plt import numpy as np import plotly from mpl_toolkits.basemap import Basemap file = ds("spdmax_MM5I_ccsm_2038010106.nc")
lat = file.variables['lat'][:] lon = file.variables['lon'][:] time = file.variables['time'][:] wind = file.variables['spdmax'][:]
map = Basemap(projection='merc',llcrnrlon=-110.0,llcrnrlat=20.0,urcrnrlon=-140.0,urcrnrlat=50.0,resolution='i')
map.drawcoastlines() map.drawstates() map.drawcountries() map.drawlsmask(land_color='Linen', ocean_color='#CCFFFF')
parallels = np.arange(15.0,55.0,5.0) meridians = np.arange(-145.0,-105.0,5.0) map.drawparallels(parallels,labels=[1,0,0,0],fontsize=10) map.drawmeridians(meridians,labels=[0,0,0,1],fontsize=10) ' Please also see the attached screenshot which has detailed pictures of our problem!