python - 如何将背景图像添加到仪表板 - 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)
解决方案
推荐阅读
- groovy - 如何正确格式化我的 URl 以使用图形 APi 过滤器
- python - 检查图像的 RGB 值是否满足没有循环的条件
- html - 如何避免 CSS 网格拉伸行?
- javascript - 如何避免重复相同的功能并使其在 Javascript 中通用
- sql - 在 FROM 语句中使用查询参数
- linux - 文件未在存储和公用文件夹之间同步
- java - 使用名为 Wait 的变量声明特征会导致覆盖编译器错误
- html - 在浏览器中测试 Quill 生成的 HTML
- html - 使用 href 在 HTML 中传递参数
- python - 如何在python中使用csv文件中的边框构建表格