最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Overlay a raster image with the component scattermap (plotly) in streamlit - Stack Overflow

programmeradmin1浏览0评论

Type With a streamlit application, I try to add a georeferenced raster image in the scattermap graph. a fixed image appears on the top left of the map, the image seems not well georeferenced, and does not move with the map when I change the zoom and center of the map.

My code :


import streamlit as st
import pandas as pd
import plotly.graph_objs as go
import plotly.express as px
import imageio
import numpy as np
from PIL import Image

# Titre de l'application
st.title("Scattermap avec Image Raster en Fond")

# Charger les données pour le scattermap
df = pd.read_csv(r"df2.csv")

# Lire l'image PNG et la convertir en tableau numpy
image = imageio.imread(r"raster_img.png")
image_array = np.array(image)
# image_array = image_array[::10, ::10]  # Décimer l'image pour la rendre plus légère

# Convertir le tableau numpy en image PIL
pil_image = Image.fromarray(image_array)
img = px.imshow(image_array)

# Créer un scattermap avec Plotly Express
fig = px.scatter_map(
    data_frame=df,
    lat="x",
    lon="y",
    zoom=8,
    opacity=0.5,
    map_style="carto-positron",
    title="ceci est un titre"
)

# Ajouter l'image à la mise en page de la carte
fig.add_layout_image(
    dict(
        pil_image,
        xref="x",  # Référence de l'axe x
        yref="y",  # Référence de l'axe y
        x=-25,  # Coordonnée x de l'image
        y=18,  # Coordonnée y de l'image
        xanchor="left",  # Ancrage de l'image sur l'axe x
        yanchor="top",  # Ancrage de l'image sur l'axe y
        sizex=22,  # Taille en x de l'image
        sizey=12,  # Taille en y de l'image
        sizing="stretch",
        opacity=0.5,
        layer="above"  # Placer l'image derrière la carte
    )
)

st.plotly_chart(fig, theme=None, on_select="rerun", selection_mode="lasso")
   
发布评论

评论列表(0)

  1. 暂无评论