0

I am trying to make a map of a wind farm. I would like to use an image of a wind turbine that I found online as the marker to show the locations of the turbines on the map. I have two problems:

  1. although i was able to import the image using the following code below, I cannot visualize it...

  2. I do not know how to define it as the marker I would like to use (which by the way, will require that I resize it...)

Here is my attempt:

from IPython.display import Image
im = Image('path/turb.png')
display (im)

Out: result

But it should be this: turbine

As for the mapping, I tried the following... without success:


fig, ax = plt.subplots(figsize = (10,10))
turb.plot(ax=ax, marker = im)

plt.show()

I got this error:

---------------------------------------------------------------------------
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'
nalfahel
  • 145
  • 9

1 Answers1

1

Here is a demo code and its resulting plot for the question.

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()

windmills

swatchai
  • 17,400
  • 3
  • 39
  • 58
  • @nalfahel Please ask as a new question and post all the relevant code, plus sample data. People will see and help. – swatchai Aug 10 '21 at 23:16