在Geopandas上的国家 /地区添加自定义图像

发布于 2025-02-04 12:30:12 字数 280 浏览 2 评论 0原文

我是Geopandas的新手,我想在数据框架中的特定国家 /地区添加自己的图像。我创建了一个示例图像以进行澄清。我想将可乐jpg添加到美国,pepsi.jpg到俄罗斯等等。

有什么办法做到这一点吗? 谢谢。

I'm new to geopandas and I want to add my own images on top of the specific countries that are in my dataframe. I created a sample image for clarification. I want to add coke.jpg to the United States, pepsi.jpg to the Russia and so on.

Is there any way to do this?
Thanks.

Sample image.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执妄 2025-02-11 12:30:12

我认为这不容易与地理杂质一起使用,因为它需要对您的图像进行地理化的坐标,这听起来很棘手(OFC并非不可能)。

但是,您可以使用基础Matplotlib子图并在其上注释图像。

请参阅下面的代码,灵感来自此源
https://moonbooks.org/articles/how-to-to-to-insert-an-image-a-picture-picture-or-a-photo-in-a-a-matplotlib-figure/

from matplotlib import pyplot as plt
import geopandas as gpd
import matplotlib.cbook as cbook

# load example image
with cbook.get_sample_data('grace_hopper.jpg') as image_file:
    image = plt.imread(image_file)

# load example map
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))

f, ax = plt.subplots()

# plot example image
# specify extent of png on canvas
# use zorder to force image to be in the upper layer
im = ax.imshow(
    image,
    extent=(-20, 20, -20, 20),
    zorder=1
)
# plot map
world.plot(ax=ax, zorder=0)

# plot map
plt.show()

i dont think this will work easily with geopandas, since it requires georeferenced coordinates for your images which sounds tricky (ofc not impossible) for jpgs.

however you could use the underlying matplotlib subplot and annotate an image on that.

see my code below, inspired by this source
https://moonbooks.org/Articles/How-to-insert-an-image-a-picture-or-a-photo-in-a-matplotlib-figure/

from matplotlib import pyplot as plt
import geopandas as gpd
import matplotlib.cbook as cbook

# load example image
with cbook.get_sample_data('grace_hopper.jpg') as image_file:
    image = plt.imread(image_file)

# load example map
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))

f, ax = plt.subplots()

# plot example image
# specify extent of png on canvas
# use zorder to force image to be in the upper layer
im = ax.imshow(
    image,
    extent=(-20, 20, -20, 20),
    zorder=1
)
# plot map
world.plot(ax=ax, zorder=0)

# plot map
plt.show()

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文