You can generate dynamic maps by passing a numpy array to ImageOverlay.
Requirements
numpy must be installed.- You must provide a
colormap argument.
Colormap Format
The colormap must be a function (e.g., a lambda) that accepts a value x and returns an RGBA tuple: lambda x: (R, G, B, A), where R, G, B, A are floats between 0 and 1.
Handling Orientation and Projection
origin='lower': Use this to inform Folium that the first lines of the array should be plotted at the bottom of the image (matching numpy.imshow behavior).mercator_project=True: Because Leaflet uses Mercator projection, raw numpy arrays may not align correctly with geographic coordinates (like Polylines). Setting mercator_project=True allows Folium to handle the projection math so the array aligns with the map's coordinate system.
import numpy as np
import folium
# Create a dummy numpy array
image = np.zeros((61, 1))
image[45, :] = 1.0
m = folium.Map([37, 0], zoom_start=3)
# Add a polyline to verify alignment
folium.PolyLine([[45, -60], [45, 60]]).add_to(m)
# Use ImageOverlay with mercator_project=True for correct alignment
folium.raster_layers.ImageOverlay(
image=image,
bounds=[[0, -60], [60, 60]],
origin="lower",
colormap=lambda x: (1, 0, 0, x),
mercator_project=True,
).add_to(m)