Maison > Article > développement back-end > [Tutoriel Python] Visualisation géographique, partie 2
Basemap是Matplotlib的一个子包,负责地图绘制。昨天的推送对如何绘制风向图进行了描述,本文再次利用该包简单介绍如何绘制海洋及海冰温度彩色图示,该图常见于NOAA官网。具体操作如下:
导入命令
1)设置工作环境并导入程序包
%cd "F:\\Dropbox\\python" from mpl_toolkits.basemap import Basemap from netCDF4 import Dataset, date2index import numpy as np import matplotlib.pyplot as plt from datetime import datetime
2)设定时间并读取数据
dataset = \ Dataset('http://www.ncdc.noaa.gov/thredds/dodsC/OISST-V2-AVHRR_agg') timevar = dataset.variables['time'] timeindex = date2index(date,timevar)
3)数据预处理
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)设定并绘制图示
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()
输出图像如下
以上就是【Python教程】地理可视化之二的内容,更多相关内容请关注PHP中文网(www.php.cn)!