简体   繁体   English

如何在不覆盖图形的情况下将 plotly 图形的图例向左移动?

[英]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.

相关问题 在 plotly 快递中,如何重命名轴和我的图例名称? y 轴仅显示为值,图例上的标题是可变的 - 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 update the info inside a mapbox without reloading the figure in plotly dash 如何自定义 matplotlib.figure.Figure 中的图形图形,例如更改标记大小? - How can I customize my graph figures in matplotlib.figure.Figure such as changing marker size? 我不知道如何让我的 Plotly 图表只显示整数 - I can't figure out how to make my Plotly charts show whole numbers only 如何在破折号 plotly 中绘制此数据? - How can I graph this data in dash plotly? 如何将Matplotlib自定义图例映射到Networkx图? - How can I map my Matplotlib custom legend to my Networkx graph? 隐藏图例中的图例条目 - Hide legend entries in a plotly figure 如何更改 python plotly 图形 id? - How can I change the python plotly figure id? 如何搜索绘图图形的特定属性的选项? - How can I search for the options for a particular property of a plotly figure? 我的图例颜色与我的图形线条颜色不匹配? - My figure legend colours do not match my graph line colours?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM