"Python tutorial" geo-visualization

Source: Internet
Author: User
Matplotlib is a common data-drawing package for Python, and its drawing is powerful, while Basemap is a sub-package of matplotlib, responsible for map drawing. This article briefly describes how to draw a wind map with this package. Here's how:

Import command

1) Set up the working environment and import the package

%CD "F:\\dropbox\\python" import numpy as Npimport Matplotlib.pyplot as Pltimport datetimefrom mpl_toolkits.basemap Import Basemap, shiftgridfrom netCDF4 import Dataset

3) Set the time and read the data

yyyy=1993; mm=03; dd=14; Hh=00date = Datetime.datetime (yyyy,mm,dd,hh) urlbase= "Http://nomads.ncdc.noaa.gov/thredds/dodsC/modeldata/cmd_ pgbh/"Url=urlbase+"%04i/%04i%02i/%04i%02i%02i/pgbh00.gdas.%0 4i%02i%02i%02i.grb2 "%\ (yyyy,yyyy,mm,yyyy,mm,dd,yyyy,mm,dd,hh) data = Dataset (URL)

4) Data preprocessing

latitudes = data.variables[' lat '][::-1]longitudes = data.variables[' lon '][:].tolist () Slpin = 0.01*data.variables[' PRESSURE_MSL '][:].squeeze () slp[:,0:-1] = slpin[::-1]; Slp[:,-1] = Slpin[::-1,0]u = Np.zeros ((uin.shape[0],uin.shape[1]+1), np.float64) u[:,0:-1] = uin[::-1]; U[:,-1] = Uin[::-1,0]v = Np.zeros ((vin.shape[0],vin.shape[1]+1), np.float64) v[:,0:-1] = vin[::-1]; V[:,-1] = vin[::-1,0]longitudes.append (360.); longitudes = Np.array (longitudes) lons, lats = Np.meshgrid (longitudes,latitudes)

5) Set and draw the diagram

m = Basemap (resolution= ' C ', projection= ' ortho ', lat_0=60.,lon_0=-60.) FIG1 = Plt.figure (figsize= (8,10)) ax = Fig1.add_axes ([0.1,0.1,0.8,0.8]) Clevs = Np.arange (960,1061,5) x, y = m (lons, lats) Parallels = Np.arange ( -80.,90,20.) meridians = Np.arange (0.,360.,20.) CS1 = M.contour (x,y,slp,clevs,linewidths=0.5,colors= ' K ', animated=true) CS2 = M.contourf (x,y,slp,clevs,cmap= plt.cm.rdbu_r,animated=true) ugrid,newlons = Shiftgrid (180.,u,longitudes,start=false) vgrid,newlons = Shiftgrid (180. , v,longitudes,start=false) Uproj,vproj,xx,yy = \m.transform_vector (ugrid,vgrid,newlons,latitudes,31,31,returnxy= true,masked=true) Q = M.quiver (xx,yy,uproj,vproj,scale=700) qk = Plt.quiverkey (Q, 0.1, 0.1, + M/s, labelpos= ' W ') M.drawcoastlines (linewidth=1.5) m.drawparallels (parallels) M.drawmeridians (meridians) cb = M.colorbar (CS2, "bottom", Size= "5%", pad= "2%") Cb.set_label (' HPa ') ax.set_title (' SLP and Wind Vectors ' +str (date)) Plt.show ()

The output image is as follows


The above is the "Python tutorial" geo-visualization content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.