Multiple legends are not independent in their placement and placement is not consistent
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 18.8k
- 派生
- 2.8k
- 平均合并
- 16 小时 26 分钟
- 30 天内合并 PR
- 21
描述
I am currently experimenting with the new-ish multi-legend feature. Unfortunately I seem to have stumbled across a case in which the legends are not behaving independently even though it is not clear why.
The following code demonstrates this:
from copy import deepcopy
import plotly.graph_objects as go
error_fig = {
'data': [
{
'legend': 'legend2',
'showlegend': True,
'type': 'scatter',
'x': [0, 1],
'xaxis': 'x2',
'y': [0, -1],
'yaxis': 'y2'
},
{
'legend': 'legend3',
'showlegend': True,
'type': 'scatter',
'x': [0, 1],
'xaxis': 'x3',
'y': [0, 1],
'yaxis': 'y3'
},
{
'legend': 'legend3',
'showlegend': True,
'type': 'scatter',
'x': [0, 1],
'xaxis': 'x3',
'y': [0, -1],
'yaxis': 'y3'
},
{
'legend': 'legend3',
'showlegend': True,
'type': 'scatter',
'x': [0, 1],
'xaxis': 'x3',
'y': [0, 1],
'yaxis': 'y3'
},
{
'legend': 'legend3',
'showlegend': True,
'type': 'scatter',
'x': [0, 1],
'xaxis': 'x3',
'y': [0, 1],
'yaxis': 'y3'
}
],
'layout': {
'legend2': {
'orientation': 'v',
'visible': True,
'x': 0.515,
'xanchor': 'left',
'xref': 'paper',
'y': 0.3,
'yanchor': 'top',
'yref': 'paper'
},
'legend3': {
'entrywidth': 0.2,
'entrywidthmode': 'fraction',
'orientation': 'h',
'visible': True,
'x': 0.95,
'xanchor': 'left',
'xref': 'paper',
'y': 1.0,
'yanchor': 'top',
'yref': 'paper'
},
'xaxis2': {'anchor': 'y2', 'domain': [0, 0.5]},
'xaxis3': {'anchor': 'y3', 'domain': [0.45, 0.95]},
'yaxis2': {'anchor': 'x2', 'domain': [0, 0.3]},
'yaxis3': {'anchor': 'x3', 'domain': [0.7, 1.0]}
}
}
correct_fig = deepcopy(error_fig)
correct_fig["layout"]["legend3"]["x"] = 1
fig_correct = go.Figure(correct_fig)
fig_correct.show()
fig_error = go.Figure(error_fig)
fig_error.show()
Where fig_correct produces this output upon png-download (The issue also exists in interactive mode with varying severity based on screen size):
fig_error produces this:
Which for me makes no sense as the only change that occurred was the placement of legend3 along x. I would therefore not expect legend2 to move. Additionally, for me it does not make any sense, why any large movement should occur at all, as I only changed the x-coordinate of legend3 by 0.05 .
For me the Issue only occurs when using "orientation": "h".
I am on Python 3.11.1
My pip dump:
Package Version
---------- -------
packaging 23.1
pip 22.3.1
plotly 5.17.0
setuptools 65.5.0
tenacity 8.2.3
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先使用 Plotly 5.17.0 运行提供的 Python reproduction,并比较交互模式和 PNG 输出中的水平多图例布局。未指定源文件或测试,因此请从 reproduction 中追踪图例放置和布局渲染的入口点;当移动 legend3 不再意外地移动 legend2 或导致不成比例的移动时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100