Jize Jiang
Jize Jiang

Reputation: 1

Can't get my data plotted as countour map on basemap

I am trying to plot a global map of gas emission. However, it seems that I can't get my data (NH3idx) plotted on the amp. I don't know whether the translation from lat lon coordinates to map projection coordinates wrong or I cannot read the data that I want to plot.

import numpy as np
import pylab as plt
import math
from mpl_toolkits.basemap import Basemap
import csv


dlat = 0.1
dlon = 0.1
nlat = 1800
nlon = 3600

longrid = -180 + np.arange(nlon) * dlon
latgrid = -90 + np.arange(nlat) * dlat

NH3idx = np.zeros([nlon,nlat])

with open ('NH3_2008.txt') as csvfile:
    plots = csv.reader(csvfile, delimiter=';')
    for row in plots:
        inlon = float(row[1])
        inlat = float(row[0])
        lonidx = int(abs(inlon + 180)/dlon)
        latidx = int(abs(inlat +90)/dlat)
        NH3idx[lonidx,latidx] = float(row[2])

plt.figure(figsize=(20,10))
m = Basemap(projection='cyl', llcrnrlat=-90,urcrnrlat=90,\
        llcrnrlon=-180,urcrnrlon=180,resolution='l')

y,x = np.meshgrid(latgrid, longrid)


m.drawcoastlines()
m.drawmeridians(np.arange(-180.,180.,20.))
m.drawparallels(np.arange(-90.,90.,20.))
m.drawmapboundary(fill_color='white')    

plt.contourf(x,y,NH3idx)
plt.colorbar()

plt.show()

and my data look like this:

the columns are lat, lon, emissions

Upvotes: 0

Views: 45

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339430

You need to first transform your coordinates to basemap coordinates

X,Y = m(x,y)

Then you probably want to use the basemap countour function

m.contourf(X,Y,NH3idx)

Upvotes: 0

Related Questions