首页 > 解决方案 > 如何将背景图像添加到仪表板 - plotly

问题描述

我希望在我的仪表板上添加一个背景图像,并且我想使用一个图形来描述图像的特征或观察结果,我使用 plotly 进行了编码,但效果不佳。我不确定是否应该在痕迹部分或布局部分添加图像图,背景图像根本不出来。有人可以帮忙吗?这是代码:

import plotly.express as px
import plotly.graph_objects as go
from skimage import io
import pandas as pd
import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output


df = pd.read_csv('sitedata.csv')
img = io.imread('assets/example.png')
fig = px.imshow(img)

app = dash.Dash(__name__)
server = app.server


app.layout = html.Div([
    # html.Img(src='assets/example.png'),
    dcc.Graph(id='sitemap'),
    dcc.Slider(
        id='dateslider',
        min=df['Number'].min(),
        max=df['Number'].max(),
        value=df['Number'].min(),
        marks={str(num): str(num) for num in df['Number'].unique()},
        step=None
    )
])

@app.callback(
    Output('sitemap', 'figure'),
    [Input('dateslider', 'value')]
)

def update_figure(selected_num):
    filtered_df = df[df['Number'] == selected_num]
    traces = []
    for i in filtered_df['Location'].unique():
        df_location = filtered_df[filtered_df['Location'] == i]
        traces.append(fig)
        traces.append(dict(
            x=df_location['Lat'],
            y=df_location['Lon'],
            text=df_location['Location'],
            mode='markers',
            marker={
                'size': df_location['Result'],
            },
            name=i,
            )
        ),


    return {
        'data': traces,
        'layout': dict(

            xaxis={'type': 'log', 'title': 'Test Sample'},
            yaxis={'title': " "}
        )
    }


if __name__ == '__main__':
    app.run_server(debug=True)

标签: pythoncallbackplotlydashboardplotly-dash

解决方案


推荐阅读