其他
Python兰勃脱投影2(附中国区域1~5级水系、湖泊矢量图)
Python为兰勃脱投影(Lambert)地图添加经纬度刻度:
注:南海小地图请参考往期推文自行添加,本文不再累述。
import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.gridliner import LATITUDE_FORMATTER, LONGITUDE_FORMATTER
from cartopy.io.shapereader import Reader
import warnings;warnings.filterwarnings('ignore')
plt.rcParams['font.family'] ='Times New Roman'
plt.rcParams['font.size'] = 16
from cartopy.io.shapereader import Reader
from matplotlib import rcParams
config = {"font.family":'Times New Roman',"font.size": 16,"mathtext.fontset":'stix'}
rcParams.update(config)
# 作图
proj = ccrs.LambertConformal(central_longitude=114.5)
fig, ax1 = plt.subplots(figsize=(12,9),subplot_kw=dict(projection=proj),dpi=400)
extent=[80,135,17,53]
ax1.set_extent(extent,crs=ccrs.PlateCarree())
ax1.stock_img()
ax1.add_feature(cfeature.COASTLINE.with_scale('50m'),linewidth=0.5,zorder=2,color='k')# 添加海岸线
ax1.add_feature(cfeature.LAKES.with_scale('50m'))
ax1.add_feature(cfeature.RIVERS.with_scale('50m'))
ax1.add_feature(cfeature.OCEAN.with_scale('50m'))
ax1.add_feature(cfeature.LAND.with_scale('50m'))
ax1.tick_params(axis='both',labelsize=12,direction='out',length=4,width=1.2,right=False,top=False)#修改刻度样式
ax1.add_geometries(Reader(r'F:/Rpython/lp27/data/river1.shp').geometries(),ccrs.PlateCarree(),facecolor='none',edgecolor='b',linewidth=0.2)
ax1.add_geometries(Reader(r'F:/Rpython/lp27/data/china1.shp').geometries(),ccrs.PlateCarree(),facecolor='none',edgecolor='k',linewidth=1.2)
ax1.add_geometries(Reader(r'F:/Rpython/lp27/data/china2.shp').geometries(),ccrs.PlateCarree(),facecolor='none',edgecolor='k',linewidth=0.8)
ax1.add_geometries(Reader(r'F:/Rpython/lp27/data/ne_50m_lakes.shp').geometries(),ccrs.PlateCarree(),facecolor='none',edgecolor='k',linewidth=0.2)
ax1.add_geometries(Reader(r'F:/Rpython/lp37/data37/river/1级河流.shp').geometries(),ccrs.PlateCarree(),facecolor='none',edgecolor='RoyalBlue',linewidth=0.4)
ax1.add_geometries(Reader(r'F:/Rpython/lp37/data37/river/2级河流.shp').geometries(),ccrs.PlateCarree(),facecolor='none',edgecolor='DodgerBlue',linewidth=0.3)
ax1.add_geometries(Reader(r'F:/Rpython/lp37/data37/river/3级河流.shp').geometries(),ccrs.PlateCarree(),facecolor='none',edgecolor='DeepSkyBlue',linewidth=0.2)
ax1.add_geometries(Reader(r'F:/Rpython/lp37/data37/river/4级河流.shp').geometries(),ccrs.PlateCarree(),facecolor='none',edgecolor='SkyBlue',linewidth=0.15)
ax1.add_geometries(Reader(r'F:/Rpython/lp37/data37/river/5级河流.shp').geometries(),ccrs.PlateCarree(),facecolor='none',edgecolor='LightSkyBlue',linewidth=0.05)
ax1.add_geometries(Reader(r'F:/Rpython/lp37/data37/river/主要湖泊.shp').geometries(),ccrs.PlateCarree(),edgecolor='none',linewidth=0,facecolor='#BEE8FF')
# 坐标与经纬网格(兰伯特投影)
fig.canvas.draw()
xticks = [lon for lon in np.arange(70,160,10)]
yticks = [lat for lat in np.arange(0,60,10)]
ax1.gridlines(xlocs=xticks, ylocs=yticks, linewidth=1.2, linestyle='--')
ax1.xaxis.set_major_formatter(LONGITUDE_FORMATTER)
ax1.yaxis.set_major_formatter(LATITUDE_FORMATTER)
import lambert_ticks
lambert_ticks.lambert_xticks(ax1, xticks)
lambert_ticks.lambert_yticks(ax1, yticks)
plt.tick_params(labelsize=16)
font3={'family':'SimHei','size':16,'color':'k'}
plt.ylabel("纬度",fontdict=font3)
plt.xlabel("经度",fontdict=font3)
ax1.set_title("中国区域DEM地形图",fontdict=font3)
plt.savefig('F:/Rpython/lp37/plot166.4.png',dpi=800,bbox_inches='tight',pad_inches=0)
plt.show()
获取本文Python兰勃脱投影2数据和代码的途径,
气象水文科研猫公众号后台回复:
“Python兰勃脱投影2”,
获取百度云免费下载链接。
**************************************
欢迎加气象水文科研猫主编微信,
获取更多免费代码和科研数据。