[Python Tutorial] 2. geographic visualization

Source: Internet
Author: User
Basemap is a child package of Matplotlib, which is used to draw maps. Yesterday's push described how to draw a wind direction chart. this article again uses this package to briefly introduce how to draw a color chart of the sea and sea ice temperature, which is common on the NOAA official website. The specific operation is as follows: Basemap is a child package of Matplotlib, which is used for map drawing. Yesterday's push described how to draw a wind direction chart. this article again uses this package to briefly introduce how to draw a color chart of the sea and sea ice temperature, which is common on the NOAA official website. The procedure is as follows:

Import command

1) set the working environment and import the package

%cd "F:\\Dropbox\\python"from mpl_toolkits.basemap import Basemapfrom netCDF4 import Dataset, date2indeximport numpy as npimport matplotlib.pyplot as pltfrom datetime import datetime

2) set the time and read data

dataset = \Dataset('http://www.ncdc.noaa.gov/thredds/dodsC/OISST-V2-AVHRR_agg')timevar = dataset.variables['time']timeindex = date2index(date,timevar)

3) Data preprocessing

sst = dataset.variables['sst'][timeindex,:].squeeze()ice = dataset.variables['ice'][timeindex,:].squeeze()lats = dataset.variables['lat'][:]lons = dataset.variables['lon'][:]lons, lats = np.meshgrid(lons,lats)

4) set and draw an illustration

fig = plt.figure()ax = fig.add_axes([0.05,0.05,0.9,0.9])m = Basemap(projection='kav7',lon_0=0,resolution=None)m.drawmapboundary(fill_color='0.3')im1 = m.pcolormesh(lons,lats,sst,shading='flat',cmap=plt.cm.jet,latlon=True)im2 = m.pcolormesh(lons,lats,ice,shading='flat',cmap=plt.cm.gist_gray,latlon=True)m.drawparallels(np.arange(-90.,99.,30.))m.drawmeridians(np.arange(-180.,180.,60.))cb = m.colorbar(im1,"bottom", size="5%", pad="2%")ax.set_title('SST and ICE analysis for %s'%date)plt.show()

The output image is as follows:

The above is the content of geographic visualization 2 in the [Python Tutorial]. For more information, see The PHP Chinese website (www.php1.cn )!

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.