【发布时间】:2021-03-03 20:47:45
【问题描述】:
有没有办法使用自定义库here 用类似于 R 解决方案的图像填充国家/地区:
我有一个填充面部颜色的解决方案,例如下面的意大利是蓝色的。但是,我想添加意大利国旗。 Python中有没有办法(搜索后我没有找到太多)或者需要像QGIS这样的东西:
#create a map where I can load images in to fill the countries
import cartopy
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import cartopy.io.shapereader as shpreader
flag = "italy.png" #this is a locally saved png.
plt.figure(figsize=(15, 15)) #size of plot
ax = plt.axes(projection=cartopy.crs.TransverseMercator(25))
ax.add_feature(cartopy.feature.BORDERS, linestyle='-', alpha=1)
ax.coastlines(resolution='110m') #simplifies the border lines
ax.add_feature(cartopy.feature.OCEAN, facecolor="#40e0d0") #colour of ocean
# ax.gridlines() #adds global grid lines
ax.set_extent ((-7.5, 50, 34, 69), cartopy.crs.PlateCarree()) #makes it european
shpfilename = shpreader.natural_earth(resolution='110m',
category='cultural',
name='admin_0_countries')
for country in shpreader.Reader(shpfilename).records():
if country.attributes['NAME_LONG'] == "Italy":
ax.add_geometries(country.geometry, ccrs.PlateCarree(),
facecolor="blue",
#no attribute like this img= "fd",
label=country.attributes['NAME_LONG'])
plt.show()
任何帮助,非常感谢!
【问题讨论】:
-
仅供参考。对于新用户,在获得 25 分之前,您不能投票给我的答案吗?声望点。但是您可以将其标记为“已接受”,并获得“+2”声望。 stackoverflow.com/help/someone-answers
标签: python matplotlib geospatial matplotlib-basemap cartopy