[英]Unable to add background image to Plotly Express data visualization
我正在嘗試在 Plotly Express 中使用背景圖像,但它似乎從未出現過。 我在 StackOverflow 上嘗試了各種其他選項,但到目前為止都沒有奏效。 這是我目前正在使用的代碼:
fig = px.scatter(df, x="X", y="Y", color="teamId", hover_name="NickName", animation_frame="GameTime", animation_group="NickName", range_x=[-4,110], range_y=[-4,72], size='size', size_max=8, width=900, height=700, color_discrete_map=color_discrete_map, title="Animated Match Recreation")
# Remove side scale and hide zero and gridlines
fig.update_layout(
coloraxis_showscale=False,
xaxis=dict(showgrid=False, zeroline=False),
yaxis=dict(showgrid=False, zeroline=False),
)
# Disable axis ticks and labels
fig.update_xaxes(showticklabels=False)
fig.update_yaxes(showticklabels=False)
fig.update_xaxes(title_text='')
fig.update_yaxes(title_text='')
# Background image file
image_file = 'WhitePitch.png'
image_path = os.path.join(os.getcwd(),image_file)
fig.add_layout_image(
dict(
source=image_path,
xref="x",
yref="y",
x=0,
y=0,
sizex=100,
sizey=70,
sizing="stretch",
opacity=0.5,
layer="below")
)
# Sets background to white vs grey
fig.update_layout(template="plotly_white")
app = dash.Dash()
app.layout = html.Div([
dcc.Graph(figure=fig)
])
app.run_server(debug=True, use_reloader=False)
任何有用的提示將不勝感激。 謝謝。
缺少此關鍵信息:
從 PIL 導入圖像 img = Image.open('Orientation_map.png')
這行得通,這是唯一對我有用的東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.