绘制science研究区域概况图

Python绘制研究区域概况图:

import numpy as np
import matplotlib.pyplot as plt
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.io.shapereader import Reader
from matplotlib import pyplot as plt
from matplotlib.colors import LightSource, ListedColormap
from mpl_toolkits.axes_grid1 import make_axes_locatable
from osgeo import gdal
from osgeo import osr
from matplotlib import rcParams
config = {"font.family":'Times New Roman',"font.size":18,"mathtext.fontset":'stix'}
rcParams.update(config)
# 设置DEM路径
dem_file = "./china_dem.tif"
# 使用GDAL驱动并读取DEM数据
ds = gdal.Open(dem_file)
tif_proj =ds.GetProjection()
tif_geotrans =ds.GetGeoTransform()
#确保TIFF的坐标系统信息
tif_crs = osr.SpatialReference(wkt=tif_proj)
# 读取TIFF数据到numpy数组
band = ds.GetRasterBand(1)
data = band.ReadAsArray()
# 设置无效值
nodata = ds.GetRasterBand(1).GetNoDataValue()
if np.any(data == nodata):
    data = np.ma.masked_equal(data, nodata)
ls=LightSource(azdeg=360,altdeg=30)
# 自定义色带
colors = ["#2B6743","#80A363","#F0EF9B","#C79F4B","#923100","#692610", "#470900"]
cmap = ListedColormap(colors)
rgb=ls.shade(data,cmap=cmap,blend_mode='overlay',vert_exag=2,dx=10,dy=10,fraction=1.05)
region=[70, 140, 15, 55]
fig = plt.figure(figsize=(16,9))
ax = fig.add_subplot(111,projection=ccrs.PlateCarree())
proj=ccrs.PlateCarree()
ax.set_extent(region, crs = proj)
ax.stock_img()
extent=(tif_geotrans[0],tif_geotrans[0]+tif_geotrans[1]*data.shape[1],tif_geotrans[3]+tif_geotrans[5]*data.shape[0],tif_geotrans[3])
img = ax.imshow(rgb,aspect='auto',origin='upper',cmap=cmap,extent=extent,transform=ccrs.PlateCarree())
# 设置colorbar
img2 = ax.imshow(data,cmap=cmap)
cbar=plt.colorbar(img2,shrink=0.85,orientation='vertical',extend='both',pad=0.01,aspect=30)
cbar.set_label('DEM/m')
cbar.ax.tick_params(labelsize=12, direction='in', right=False)
ax.set_xticks(np.arange(region[0], region[1] + 1, 10), crs = proj)
ax.set_yticks(np.arange(region[-2], region[-1] + 1, 10), crs = proj)
ax.xaxis.set_major_formatter(LongitudeFormatter(zero_direction_label=False))
ax.yaxis.set_major_formatter(LatitudeFormatter())
ax.add_geometries(Reader(r'./China_Province.shp').geometries(),ccrs.PlateCarree(),facecolor='none',edgecolor='black',linewidth=0.8)
ax.add_geometries(Reader(r'./10line.shp').geometries(),ccrs.PlateCarree(),facecolor='none',edgecolor='black',linewidth=0.8)
ax.add_feature(cfeature.COASTLINE.with_scale('50m'),linewidth=0.5,zorder=2,color='k')# 添加海岸线
ax.add_feature(cfeature.LAKES.with_scale('50m'))
ax.add_feature(cfeature.RIVERS.with_scale('50m'))
ax.add_feature(cfeature.OCEAN.with_scale('50m'))
ax.add_feature(cfeature.LAND.with_scale('50m'))
ax.add_geometries(Reader(r'./river1.shp').geometries(),ccrs.PlateCarree(),facecolor='none',edgecolor='b',linewidth=0.2)
ax.add_geometries(Reader(r'./ne_50m_lakes.shp').geometries(),ccrs.PlateCarree(),facecolor='none',edgecolor='k',linewidth=0.2)
ax.add_geometries(Reader(r'./1级河流.shp').geometries(),ccrs.PlateCarree(),facecolor='none',edgecolor='RoyalBlue',linewidth=0.4)
ax.add_geometries(Reader(r'./2级河流.shp').geometries(),ccrs.PlateCarree(),facecolor='none',edgecolor='DodgerBlue',linewidth=0.3)
ax.add_geometries(Reader(r'./3级河流.shp').geometries(),ccrs.PlateCarree(),facecolor='none',edgecolor='DeepSkyBlue',linewidth=0.2)
ax.add_geometries(Reader(r'./4级河流.shp').geometries(),ccrs.PlateCarree(),facecolor='none',edgecolor='SkyBlue',linewidth=0.15)
ax.add_geometries(Reader(r'./5级河流.shp').geometries(),ccrs.PlateCarree(),facecolor='none',edgecolor='LightSkyBlue',linewidth=0.05)
ax.add_geometries(Reader(r'./主要湖泊.shp').geometries(),ccrs.PlateCarree(),edgecolor='none',linewidth=0,facecolor='#BEE8FF')
ax.set_title('中国立体DEM地形图【审图号GS(2024)0650号】',{'family':'simhei','size':18,'color':'k'})
plt.savefig('./plot330.8.2.png',dpi=200,bbox_inches='tight',pad_inches=0)
plt.show()

图片

图片

图片

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-13 12:16:01       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-13 12:16:01       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-13 12:16:01       58 阅读
  4. Python语言-面向对象

    2024-07-13 12:16:01       69 阅读

热门阅读

  1. 音频筑基:入门50问

    2024-07-13 12:16:01       28 阅读
  2. 永恒之蓝:一场网络风暴的启示

    2024-07-13 12:16:01       30 阅读
  3. TensorFlow系列:第三讲:MobileNetV2使用介绍

    2024-07-13 12:16:01       24 阅读
  4. MySQL上亿数据查询优化:实践与技巧

    2024-07-13 12:16:01       20 阅读
  5. Jetson-AGX-Orin gstreamer+rtmp+http-flv 推拉流

    2024-07-13 12:16:01       20 阅读
  6. Mybatis-Plus最优化持久层开发

    2024-07-13 12:16:01       18 阅读
  7. 389. 找不同

    2024-07-13 12:16:01       20 阅读
  8. Python水平怎么样才能就业?

    2024-07-13 12:16:01       49 阅读
  9. Git: fatal: cannot lock ref‘HEAD‘: Unable to create

    2024-07-13 12:16:01       25 阅读
  10. 大数据学习之 scala基础(补充)

    2024-07-13 12:16:01       24 阅读
  11. Perl中的切分艺术:深入探索split函数的神秘力量

    2024-07-13 12:16:01       22 阅读
  12. 【面试题】Golang 之Channel底层原理 (第三篇)

    2024-07-13 12:16:01       22 阅读
  13. 数据结构

    2024-07-13 12:16:01       26 阅读
  14. MySQL 面试题

    2024-07-13 12:16:01       25 阅读