0

I'm new to python and still learning, so forgive me if I missed something obvious!

I'm trying to plot a pcolormesh map of temperature data ('tg') using Basemap in matplotlib. tg is a 3D array of time, latitudes and longitudes. For some reason, my output only shows the continent and states, but the temperature data is not overlain and is not visible. What am I missing?

Here is a sample of my code:

import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap, cm

lon_0 = (lon_var[:].mean())
lat_0 = (lat_var[:].mean())
latcorners = lat_var[:]
loncorners = lon_var[:]

m = Basemap(projection = 'lcc',\
        lon_0 = -100, lat_0 = 39, lat_ts = lat_0,\
        llcrnrlat=latcorners[0,0],urcrnrlat=latcorners[169,56],\
        llcrnrlon=loncorners[0,0],urcrnrlon= loncorners[169,56],\
        resolution='l')

m.drawcoastlines()
m.drawstates()
m.drawcountries()

parallels = np.arange(lat_var[0,0], lat_var[169,56])
m.drawparallels(parallels)

meridians = np.arange(lon_var[0,0], lon_var[169,56])
m.drawmeridians(meridians)


clevs = np.linspace(30,50, 2)

cs = m.pcolormesh(lon_var, lat_var, tg[0,:,:])
plt.show()

Here is the output map that is created

Thanks!

k.mcgee
  • 96
  • 5
  • Try `m.pcolormesh(lon_var, lat_var, tg[0,:,:], latlon=True)`. – Thomas Kühn Feb 27 '18 at 16:20
  • @Thomas Kuhn This ended up working! I also noticed that my lon_var and lat_var were both in the wrong data types. I converted them with np.array() and then the script ran successfully. Thanks for your help! – k.mcgee Feb 27 '18 at 22:34
  • Maybe you could write an answer to your own question -- this way other's can see that this question needs no further attention. – Thomas Kühn Feb 28 '18 at 06:59
  • Possible duplicate of [scatter plot data does not appear on continents in 'hammer' basemap](https://stackoverflow.com/questions/29590365/scatter-plot-data-does-not-appear-on-continents-in-hammer-basemap) – Bart Mar 16 '18 at 06:01

1 Answers1

1

Problem solved! My final command:

m.pcolormesh(lon_var, lat_var, tg[0,:,:], latlon = True)

the latlon = True keyword argument was required to properly display my data. Separately, I realized that lat_var and lon_var were read over as lists, and needed to convert these into arrays with np.array().

k.mcgee
  • 96
  • 5