簡體   English   中英

如何在不覆蓋圖形的情況下將 plotly 圖形的圖例向左移動?

[英]How can I move the legend of a plotly figure to the left without covering my graph?

我有以下 Plotly 圖。 我正在使用 Dash 創建儀表板。 我設法將圖例向左移動,但它現在覆蓋了我實際圖表的一部分。 我怎樣才能避免這種情況?

這是圖表

這是我用來創建圖形並更新其布局的代碼:

fig2=px.line(df_tradef2,x='Year', y='Value', title=Measures2+' - '+district2, color='Commodity',  width=1200, height=650)
fig2.update_xaxes(nticks=len(pd.unique(df_tradef2['Year'])), rangeslider_visible=True)
fig2.update_layout(yaxis_range=[start2,end2])
fig2.update_layout(legend=dict(
    orientation="v",
    yanchor="auto",
    y=1,
    xanchor="auto",
    x=-0.3
    ))

您可以嘗試將圖例的錨點更改為right

fig2.update_layout(legend=dict(
    orientation="v",
    yanchor="auto",
    y=1,
    xanchor="right",  # changed
    x=-0.3
    ))

這將確保圖例框的右側位於紙張坐標中 y 軸左側的 30% 處。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM