Home > Backend Development > Python Tutorial > [Python Tutorial] Geographic Visualization Part 2

[Python Tutorial] Geographic Visualization Part 2

黄舟
Release: 2017-02-07 16:24:32
Original
1932 people have browsed it

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
Copy after login

2)设定时间并读取数据

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

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)
Copy after login

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()
Copy after login

输出图像如下

[Python Tutorial] Geographic Visualization Part 2


以上就是【Python教程】地理可视化之二的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template