簡體   English   中英

在 cartopy map 上添加具有給定坐標(緯度、經度)的圖像

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

我想通過一個小圖像/圖標在cartopy map 上標記某個位置(緯度,經度)。 我怎樣才能做到這一點?

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. 有沒有其他方法可以做到這一點?

非常感謝..

以下對我來說很好:

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)

您可能想通過將zoom更改為更大的值或將frameon設置為True來嘗試調試。 如果您還有其他問題,請務必發布您的 lon/lat 值。

我嘗試了您鏈接的要點中的代碼,因為它使用 cartopy 對圖像進行地理配准。 我得到以下結果:

世界 map 與中國國旗

這是你想要的效果嗎? 我在從 gist 復制的代碼中唯一更改的是圖片。 我用過這個

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM