在 Geopandas 中使用图像作为地图上的标记
Using an image as marker on a map in Geopandas
我正在尝试制作风电场的地图。我想使用我在网上找到的风力涡轮机图像作为标记,以在地图上显示涡轮机的位置。我有两个问题:
尽管我可以使用下面的代码导入图像,但我无法将其可视化...
我不知道如何将它定义为我想使用的标记(顺便说一下,这需要我调整它的大小...)
这是我的尝试:
from IPython.display import Image
im = Image('path/turb.png')
display (im)
输出:
但应该是这样的:
至于映射,我尝试了以下...但没有成功:
fig, ax = plt.subplots(figsize = (10,10))
turb.plot(ax=ax, marker = im)
plt.show()
我收到这个错误:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-53-d26dd941b982> in <module>()
1 minx, miny, maxx, maxy = ri.geometry.total_bounds
2 fig, ax = plt.subplots(figsize = (10,10))
----> 3 turb.plot(ax=ax, marker = im)
4 ri.plot(ax=ax)
5 #ax.set_xlim(minx, maxx) # added/substracted value is to give some margin around total bounds
11 frames
/usr/local/lib/python3.7/dist-packages/numpy/core/_asarray.py in asarray(a, dtype, order)
81
82 """
---> 83 return array(a, dtype, copy=False, order=order)
84
85
TypeError: float() argument must be a string or a number, not 'Image'
这是一个演示代码及其生成的问题图。
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.offsetbox import OffsetImage, AnnotationBbox
path = "./images/YCcBa.png"
image = plt.imread(path)[10:10+128, 10:10+108]
def plot_images(x, y, image, ax):
for xi, yi in zip(x,y):
im = OffsetImage(image, zoom=72/ax.figure.dpi)
im.image.axes = ax
# create bbox for the images
ab = AnnotationBbox(im, (xi,yi), frameon=False, pad=0.0)
ax.add_artist(ab)
x = np.arange(10)
y = np.random.rand(10)
fig, ax = plt.subplots(figsize = (8,8))
plot_images(x, y, image, ax)
ax.plot(x, y) # plot lines connecting (x,y)'s
plt.show()
我正在尝试制作风电场的地图。我想使用我在网上找到的风力涡轮机图像作为标记,以在地图上显示涡轮机的位置。我有两个问题:
尽管我可以使用下面的代码导入图像,但我无法将其可视化...
我不知道如何将它定义为我想使用的标记(顺便说一下,这需要我调整它的大小...)
这是我的尝试:
from IPython.display import Image
im = Image('path/turb.png')
display (im)
输出:
但应该是这样的:
至于映射,我尝试了以下...但没有成功:
fig, ax = plt.subplots(figsize = (10,10))
turb.plot(ax=ax, marker = im)
plt.show()
我收到这个错误:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-53-d26dd941b982> in <module>()
1 minx, miny, maxx, maxy = ri.geometry.total_bounds
2 fig, ax = plt.subplots(figsize = (10,10))
----> 3 turb.plot(ax=ax, marker = im)
4 ri.plot(ax=ax)
5 #ax.set_xlim(minx, maxx) # added/substracted value is to give some margin around total bounds
11 frames
/usr/local/lib/python3.7/dist-packages/numpy/core/_asarray.py in asarray(a, dtype, order)
81
82 """
---> 83 return array(a, dtype, copy=False, order=order)
84
85
TypeError: float() argument must be a string or a number, not 'Image'
这是一个演示代码及其生成的问题图。
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.offsetbox import OffsetImage, AnnotationBbox
path = "./images/YCcBa.png"
image = plt.imread(path)[10:10+128, 10:10+108]
def plot_images(x, y, image, ax):
for xi, yi in zip(x,y):
im = OffsetImage(image, zoom=72/ax.figure.dpi)
im.image.axes = ax
# create bbox for the images
ab = AnnotationBbox(im, (xi,yi), frameon=False, pad=0.0)
ax.add_artist(ab)
x = np.arange(10)
y = np.random.rand(10)
fig, ax = plt.subplots(figsize = (8,8))
plot_images(x, y, image, ax)
ax.plot(x, y) # plot lines connecting (x,y)'s
plt.show()