Cannot increase distance between shape and its label outside of the object
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 18.8k
- 派生
- 2.8k
- 平均合并
- 16 小时 26 分钟
- 30 天内合并 PR
- 21
描述
Challenge
I would like to draw a shape using the label argument to position the label outside of the shape. Unfortunately, the label always touches the shape and padding only works in one direction: towards the center of the shape.
Here is an example:
import plotly.graph_objects as go
fig = go.Figure()
for i in range(0, 4):
fig.add_shape(
go.layout.Shape(
type="rect",
x0=10,
y0=10*i + 3,
x1=15,
y1=10*i + 10,
label={
"text": f"Padding: {i*10}px",
"textposition": "middle right",
"xanchor": "left",
"yanchor": "middle",
"padding": i*10,
},
)
)
fig.update_layout(xaxis_range=[0, 20], yaxis_range=[0, 60])
fig.show()
Despite seting xanchor="left" and textposition="middle right", the label barely touches the shape (for padding=0) and with increasing padding the label always moves towards the center.
Setting padding to a negative value seems not to be allowed:
ValueError:
Invalid value of type 'builtins.int' received for the 'padding' property of layout.shape.label
Received value: -10
The 'padding' property is a number and may be specified as:
- An int or float in the interval [0, inf]
Expected Behavior
Either infer from anchor and textposition, if a label should be outside of the shape, or allow negative values for padding so that I can increase the distance between the rectangle and the label.
I could not find any other info regarding this observation and I would like to avoid using an annotation as a workaround.
Am I overlooking something or is this a bug?
System Info
python: v3.10.11
plotly: v5.24.1
Working in a VSCode (v1.96.2) notebook and tested multiple different renderers with identical outcome: "vscode", "notebook", "browser".
Same result with write_image and pdf and png.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先,使用不同的 padding 值和渲染器运行提供的 go.Figure/add_shape 示例。跟踪形状标签如何处理 textposition、xanchor 和 padding;当标签无需 annotation workaround 即可向形状外侧留出间距,并且针对所演示案例具有回归覆盖时,该 issue 即完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100