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 )!