[英]In plotly express, how can I rename the axes and the name of my legend? The y-axis is only showing as values and the title on the legend is variable
[英]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.