Re: [Matplotlib-users] Basemap plotting data on projection
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] ml-node+s1069221n40977...@n5.nabble.com wrote: Forgot to send to the list sigh -- Forwarded message -- From: Scott Sinclair [hidden email]http://user/SendEmail.jtp?type=nodenode=40977i=0 Date: 30 April 2013 13:20 Subject: Re: [Matplotlib-users] Basemap plotting data on projection To: ChaoYue [hidden email]http://user/SendEmail.jtp?type=nodenode=40977i=1 On 29 April 2013 23:32, ChaoYue [hidden email]http://user/SendEmail.jtp?type=nodenode=40977i=2 wrote: pdata = np.genfromtxt('pdata.txt') pdata = np.ma.masked_greater(pdata,1E20) lonm,latm=m.makegrid(pdata.shape[1],pdata.shape[0]) 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') pdata = np.ma.masked_greater(pdata, 1E20) 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 Download for free and get started troubleshooting in minutes. http://p.sf.net/sfu/appdyn_d2d_ap1 ___ Matplotlib-users mailing list [hidden email] http://user/SendEmail.jtp?type=nodenode=40977i=3 https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- If you reply to this email, your message will be added to the discussion below: http://matplotlib.1069221.n5.nabble.com/Basemap-plotting-data-on-projection-tp40973p40977.html To start a new topic under matplotlib - users, email ml-node+s1069221n...@n5.nabble.com To unsubscribe from matplotlib, click herehttp://matplotlib.1069221.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=2code=Y2hhb3l1ZWpveUBnbWFpbC5jb218MnwxMzg1NzAzMzQx . NAMLhttp://matplotlib.1069221.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespacebreadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml -- *** 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: http://matplotlib.1069221.n5.nabble.com/Basemap-plotting-data-on-projection-tp40973p41044.html Sent from the matplotlib - users mailing list archive at Nabble.com.-- AlienVault Unified Security Management (USM) platform delivers complete security visibility with the essential security capabilities. Easily and efficiently configure, manage, and operate all of your security controls from a single console and one unified framework. Download a free trial. http://p.sf.net/sfu/alienvault_d2d___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Basemap plotting data on projection
Hi all, Indeed it's a bit strange, I can reproduce the problem. But when using 'cyl' projection I don't have this issue. attahced two figures showed the difference. the tested data is also attached. complete code is below: from mpl_toolkits.basemap import Basemap, cm, maskoceans import matplotlib.pyplot as plt # set up the Mercator projection 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='aqua') m.drawrivers() pdata = np.genfromtxt('pdata.txt') pdata = np.ma.masked_greater(pdata,1E20) lonm,latm=m.makegrid(pdata.shape[1],pdata.shape[0]) latm=np.flipud(latm) lonpro,latpro=m(lonm,latm) cs = m.contourf(lonpro,latpro,pdata) m.colorbar(cs) cheers, Chao On Mon, Apr 29, 2013 at 12:53 PM, Ann [via matplotlib] ml-node+s1069221n40973...@n5.nabble.com wrote: Dear All, I am encountering the following problem: I have some data which I want to plot on a map. Unfortunately, I do not manage to plot the data according to the shape of the projection! What it appears to do is to simply plot the data on top of the projection without taking the actual position (latitude and longitude) into account. However, this is crucial for my analysis. Could anybody spot the mistake in my code? Any suggestion would be of great help!! THANKS from mpl_toolkits.basemap import Basemap, cm, maskoceans import matplotlib.pyplot as plt # set up the Mercator projection 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='aqua') m.drawrivers() parallels = N.arange(0.,81,10.) labels = [left,right,top,bottom] m.drawparallels(parallels,labels=[1,0,0,0]) meridians = N.arange(10.,351.,20.) m.drawmeridians(meridians,labels=[0,0,0,1]) ny=resmat.shape[0] # resmat is the matrix containing the data which I want o plot. nx=resmat.shape[1] #get lat/lons of ny by nx evenly space grid lons, lats =m.makegrid(nx, ny) # compute map projection coordinates x, y= m(lons, lats) maskdata = maskoceans(lons, lats, resmat, inlands= True, resolution = 'l') cs = m.contourf(x,y,maskdata,150,cmap=cm.GMT_no_green_r) plt.show() -- If you reply to this email, your message will be added to the discussion below: http://matplotlib.1069221.n5.nabble.com/Basemap-plotting-data-on-projection-tp40973.html To start a new topic under matplotlib - users, email ml-node+s1069221n...@n5.nabble.com To unsubscribe from matplotlib, click herehttp://matplotlib.1069221.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=2code=Y2hhb3l1ZWpveUBnbWFpbC5jb218MnwxMzg1NzAzMzQx . NAMLhttp://matplotlib.1069221.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespacebreadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml -- *** 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 pdata.txt (413K) http://matplotlib.1069221.n5.nabble.com/attachment/40975/0/pdata.txt cyl.jpg (540K) http://matplotlib.1069221.n5.nabble.com/attachment/40975/1/cyl.jpg merc.jpg (435K) http://matplotlib.1069221.n5.nabble.com/attachment/40975/2/merc.jpg -- View this message in context: http://matplotlib.1069221.n5.nabble.com/Basemap-plotting-data-on-projection-tp40973p40975.html Sent from the matplotlib - users mailing list archive at Nabble.com.-- Try New Relic Now We'll Send You this Cool Shirt New Relic is the only SaaS-based application performance monitoring service that delivers powerful full stack analytics. Optimize and monitor your browser, app, servers with just a few lines of code. Try New Relic and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users