- 积分
- 2415
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2012-11-25
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2014-6-5 11:18:23
|
显示全部楼层
附带楼主上次提到的那个图和程序:
下面是程序:
import cartopy.io.shapereader as shpreader
from cartopy.mpl.patch import geos_to_path
file=r'D:/baiduyundownload/map/map/world map china line.shp'
reader = shpreader.Reader(file)
countries = reader.records()
us_multipoly, = [country.geometry for country in countries
if country.attributes['NAME'] == 'China']
main_us_geom = sorted(us_multipoly.geoms, key=lambda geom: geom.area)[-1]
us_path, = geos_to_path(main_us_geom)
############################
#以上地图设置阶段
############################
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import PathPatch
import cartopy.crs as ccrs
import matplotlib.ticker as mticker
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER , LATITUDE_FORMATTER
plt.figure(figsize=(10, 10))
ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_extent([70,140,10,60])
ax.coastlines()
plate_carre_data_transform = ccrs.PlateCarree()._as_mpl_transform(ax)
ax.set_title('China Plot')
line=ax.gridlines(draw_labels=True,alpha=0.5,linestyle='--')
line.xlabels_top=False
line.ylabels_left=False
#line.xlines=False#只剩下x轴平行线
line.xlocator=mticker.FixedLocator(np.arange(70,140,20))#手动设置x轴刻度
line.xformatter= LONGITUDE_FORMATTER
line.yformatter= LATITUDE_FORMATTER
line.xlabel_style={'size':10,'color':'black'}
line.yalbel_style={'color':'red','weight':'bold'}
############################
#以上地图投影设置
############################
from netCDF4 import Dataset
q=Dataset(r'D:\Desktop\model\CUR\2006pr.nc')
lon=q.variables['lon'][:]
lat=q.variables['lat'][:]
pre=q.variables['pre'][4][:]
x,y=np.meshgrid(lon,lat)
############################
#以上读取nc数据
############################
#绘制等值线
quad_set = plt.contourf(x,y,pre,cmap='spectral',transform=ccrs.PlateCarree())#绘制等值线填充
for collection in quad_set.collections:
collection.set_clip_path(us_path, plate_carre_data_transform)#设置显示区域
plt.colorbar(quad_set,orientation='horizontal',shrink=0.8,extend='both',pad=0.05)
plt.show()
|
评分
-
查看全部评分
|