0

I'm trying to produce a temperature colormap of a netcdf file with python. This is the first part of the code:

from netCDF4 import Dataset
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
my_path = 'tas_EUR-44_GISS-E2-R_historical_r1i1p3_AUTH-MC-WRF371M_v1_3hr_2005010100-2005123121.nc'
fh = Dataset(my_path, mode='r')
lons = (fh.variables['lon'][:])
lats = (fh.variables['lat'][:])
t = (fh.variables['tas'][:])
t_units = fh.variables['tas'].units
fh.close()
lon_0 = lons.mean()
lat_0 = lats.mean()
m = Basemap(width=5000000, height=3500000,
            resolution='l', projection='stere', \
            lat_ts=40, lat_0=lat_0, lon_0=lon_0)
cs = m.pcolor(lons, lats, t[0, 0, :, :])

Once arrived at this command line, it appears this warning:

/Users/me/anaconda/lib/python3.6/site-packages/mpl_toolkits/basemap/init.py:3677: MatplotlibDeprecationWarning: axes.hold is deprecated. See the API Changes document (http://matplotlib.org/api/api_changes.html) for more details. ax.hold(b)

I tried also including hold=False, but the result is the same, as you can see in the imagine: no contourf. What am I missing?

enter image description here

james
  • 153
  • 1
  • 13
Mal
  • 63
  • 1
  • 9
  • 2
    Do you try to covert lats, lons to map coordinates? Try to add a line `lons,lats = m(lons,lats)` before `m.pcolor(..)`. – Serenity Jul 21 '17 at 12:17
  • 2
    In addition to the comment from @Serenity, most plot methods now have a `latlon=True/False` keyword, with `latlon=True` the conversion from latitude/longitude to the map projection is handled automatically. – Bart Jul 21 '17 at 19:53
  • Thank you guys, you fixed my problem! – Mal Aug 01 '17 at 11:20

0 Answers0