简体   繁体   English

在 cartopy map 上添加具有给定坐标(纬度、经度)的图像

[英]add a image with given coordination (lat, lon) on the cartopy map

I want to mark some location (lat,lon) on a cartopy map by a small image/icon.我想通过一个小图像/图标在cartopy map 上标记某个位置(纬度,经度)。 how can I do that?我怎样才能做到这一点?

import cartopy.crs as crs
import matplotlib.pyplot as plt

fig = plt.figure(figsize=(10, 5))
ax = plt.axes(projection=crs.PlateCarree())
ax.stock_img()

img = plt.imread('flag.png') #the image I want to add on the map

plt.show()

I found a source here: https://gist.github.com/secsilm/37db690ab9716f768d1a1e43d3f53e3f But it doesn't work for me, the map show up without any flag. I found a source here: https://gist.github.com/secsilm/37db690ab9716f768d1a1e43d3f53e3f But it doesn't work for me, the map show up without any flag. Is there any other way to do that?有没有其他方法可以做到这一点?

Thank a lot..非常感谢..

The following worked just fine for me:以下对我来说很好:

import matplotlib.pyplot as plt
import cartopy.crs as crs
from matplotlib.offsetbox import AnnotationBbox, OffsetImage

# Read image
lat = 39
lon = -95
img = plt.imread('/Users/rmay/Downloads/flag.png')

# Plot the map
fig = plt.figure(figsize=(10, 5))
ax = plt.axes(projection=crs.PlateCarree())
ax.coastlines()
ax.stock_img()
# Use `zoom` to control the size of the image
imagebox = OffsetImage(img, zoom=.1)
imagebox.image.axes = ax
ab = AnnotationBbox(imagebox, [lon, lat], pad=0, frameon=False)
ax.add_artist(ab)

You might want to try debugging by changing zoom to larger values or setting frameon to True .您可能想通过将zoom更改为更大的值或将frameon设置为True来尝试调试。 If you have further problem, be sure to post your values for lon/lat.如果您还有其他问题,请务必发布您的 lon/lat 值。

I tried the code in the gist you linked as it uses cartopy to georeference the image.我尝试了您链接的要点中的代码,因为它使用 cartopy 对图像进行地理配准。 I got the following result:我得到以下结果:

world map with china flag世界 map 与中国国旗

Is this the effect you desired?这是你想要的效果吗? The only thing I changed in the code copied from the gist is the picture.我在从 gist 复制的代码中唯一更改的是图片。 I used this one我用过这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM