# Basemap plotting data on projection

Forgot to send to the list <sigh>

···

---------- Forwarded message ----------
From: Scott Sinclair <scott.sinclair.za@...287...>
Date: 30 April 2013 13:20
Subject: Re: [Matplotlib-users] Basemap plotting data on projection
To: ChaoYue <chaoyuejoy@...287...>

On 29 April 2013 23:32, ChaoYue <chaoyuejoy@...287...> wrote:

pdata = np.genfromtxt('pdata.txt')
lonm,latm=m.makegrid(pdata.shape,pdata.shape)

The problem is here ^^^

The data don't lie on an equally spaced grid in the Mercator
projection, so it doesn't make sense to ask for the lat/lon
coordinates of a grid that is equally spaced in this projection. You
need to determine the *actual* lat/lon coordinates before projecting
them onto the Mercator map and plotting...

Something like this should work (If you can assume that the data are
on an equally spaced grid in Equidistant Cyl projection having the
boundaries specified):

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

# Set up the Equidistant Cyl projection to determine data locations.
pdata = np.genfromtxt('pdata.txt')
ny, nx = pdata.shape

cyl_basemap = Basemap(projection='cyl', llcrnrlat=9, urcrnrlat=54.5,
llcrnrlon=74, urcrnrlon=142, lat_ts=20, resolution='l')
lon, lat = cyl_basemap.makegrid(nx, ny)

# Set up the Mercator projection for plotting.
m = Basemap(projection='merc', llcrnrlat=9, urcrnrlat=54.5,\
llcrnrlon=74, urcrnrlon=142, lat_ts=20, resolution='l')
m.drawcountries()
m.drawcoastlines()
m.drawmapboundary(fill_color='white')
m.drawrivers()

x, y = m(lon, np.flipud(lat))
cs = m.contourf(x, y, pdata)
m.colorbar(cs)
plt.show()

Cheers,
Scott

Dear Scott,

I am sorry for giving no reply. Thanks for your answer. I tried it and it works fine.

best ,

Chao

···

On Tue, Apr 30, 2013 at 1:21 PM, Scott Sinclair-4 [via matplotlib] <[hidden email]> wrote:

Forgot to send to the list

---------- Forwarded message ----------

From: Scott Sinclair <[hidden email]>

Date: 30 April 2013 13:20

Subject: Re: [Matplotlib-users] Basemap plotting data on projection

To: ChaoYue <[hidden email]>

On 29 April 2013 23:32, ChaoYue <[hidden email]> wrote:

pdata = np.genfromtxt(‘pdata.txt’)

lonm,latm=m.makegrid(pdata.shape,pdata.shape)

The problem is here ^^^

The data don’t lie on an equally spaced grid in the Mercator

projection, so it doesn’t make sense to ask for the lat/lon

coordinates of a grid that is equally spaced in this projection. You

need to determine the actual lat/lon coordinates before projecting

them onto the Mercator map and plotting…

Something like this should work (If you can assume that the data are

on an equally spaced grid in Equidistant Cyl projection having the

boundaries specified):

from mpl_toolkits.basemap import Basemap

import matplotlib.pyplot as plt

# Set up the Equidistant Cyl projection to determine data locations.

pdata = np.genfromtxt(‘pdata.txt’)

ny, nx = pdata.shape

cyl_basemap = Basemap(projection=‘cyl’, llcrnrlat=9, urcrnrlat=54.5,

``````                  llcrnrlon=74, urcrnrlon=142, lat_ts=20, resolution='l')
``````

lon, lat = cyl_basemap.makegrid(nx, ny)

# Set up the Mercator projection for plotting.

m = Basemap(projection=‘merc’, llcrnrlat=9, urcrnrlat=54.5,\

llcrnrlon=74, urcrnrlon=142, lat_ts=20, resolution=‘l’)

m.drawcountries()

m.drawcoastlines()

m.drawmapboundary(fill_color=‘white’)

m.drawrivers()

x, y = m(lon, np.flipud(lat))

cs = m.contourf(x, y, pdata)

m.colorbar(cs)

plt.show()

Cheers,

Scott

Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET

Get 100% visibility into your production application - at no cost.

Code-level diagnostics for performance bottlenecks with <2% overhead

http://p.sf.net/sfu/appdyn_d2d_ap1

Matplotlib-users mailing list

[hidden email]

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

http://matplotlib.1069221.n5.nabble.com/Basemap-plotting-data-on-projection-tp40973p40977.html

To start a new topic under matplotlib - users, email [hidden email]

``````  To unsubscribe from matplotlib, click here.

``````

Chao YUE
Laboratoire des Sciences du Climat et de l’Environnement (LSCE-IPSL)
UMR 1572 CEA-CNRS-UVSQ
Batiment 712 - Pe 119
91191 GIF Sur YVETTE Cedex

Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16

View this message in context: Re: Basemap plotting data on projection

Sent from the matplotlib - users mailing list archive at Nabble.com.