Python:如何在一个绘图中将一个形状文件放置在光栅文件的顶部,然后以Jpeg文件格式保存绘图
我在网上搜索了三天后发布了这个问题,但没有成功。希望能在这里得到答案。请不要删除帖子,因为我在这里也没有找到答案。谢谢 我有两个文件:Python:如何在一个绘图中将一个形状文件放置在光栅文件的顶部,然后以Jpeg文件格式保存绘图,python,plot,raster,shapefile,rasterio,Python,Plot,Raster,Shapefile,Rasterio,我在网上搜索了三天后发布了这个问题,但没有成功。希望能在这里得到答案。请不要删除帖子,因为我在这里也没有找到答案。谢谢 我有两个文件: 光栅图像文件(即气温2020-01-01.tif) 世界各国边界形状文件(即世界各国基本地图) 目标:我想在光栅文件的顶部打印shapefile,然后以Jpeg文件格式保存打印,最终得到如下结果: 我是Python新手,使用Spyder编写了以下简单代码: # Import needed packages import os import rasterio i
# Import needed packages
import os
import rasterio
import matplotlib.pyplot as plt
import geopandas as gpd
import earthpy as et
from matplotlib import pyplot
## list all raster images in tiff format in the folder:
list_files = [f for f in
os.listdir('C:/Users/Desktop/Question/Raster_Air_temp')
if '.tif' in f]
print(list_files[1]) # checking the 1st file in the list
## reading the first tiff file:
raster_image = rasterio.open(list_files[1])
## plot it
draft_output = pyplot.imshow(raster_image.read(1), cmap='jet')
## importing world shapefile
World_map = gpd.read_file('C:/Users/Desktop/Question/World_shapefile/World_Countries_base_map.shp')
# plot World shapefile
fig, ax = plt.subplots(figsize = (30,30)) # image size and quality can be controled by figsize
ax.set_title('The Glob Map', fontsize=50);
World_map.plot(ax=ax, color='white', edgecolor='black') # colors note at https://matplotlib.org/tutorials/colors/colormaps.html
plt.show()
## Plot both World shapefile and raster image in one graph:
????
但是,这段代码只在控制台中为我生成了两个独立的绘图,如上所示
问题:如何在代码的???部分键入正确的代码以达到我的目标(如上所述)?
感谢所有的评论和帮助
在这里,我共享这两个文件,以方便需要帮助的人。