[英]How can I move the legend of a plotly figure to the left without covering my graph?
I have the following Plotly figure.我有以下 Plotly 图。 I am using Dash to create a dashboard.我正在使用 Dash 创建仪表板。 I managed to move the legend to the left, but it is now covering a part of my actual graph.我设法将图例向左移动,但它现在覆盖了我实际图表的一部分。 How can I avoid this?我怎样才能避免这种情况?
Here is the code I used to create the figure and update its layout:这是我用来创建图形并更新其布局的代码:
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
))
You can try changing the anchoring point of the legend to right
:您可以尝试将图例的锚点更改为right
:
fig2.update_layout(legend=dict(
orientation="v",
yanchor="auto",
y=1,
xanchor="right", # changed
x=-0.3
))
This will make sure the right side of the legend box is at 30% to the left of the y-axis in paper coordinates .这将确保图例框的右侧位于纸张坐标中 y 轴左侧的 30% 处。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.