Funnel plot text does not position itself properly
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 18.3k
- 派生
- 2k
- 平均合并
- 2 天 12 小时
- 30 天内合并 PR
- 28
描述
I'm attempting to produce a stacked funnel plot of activities. The labels are not appearing as expected on the plot.
I'm reposting my question from Stack Overflow here based on the response I got there indicating this might be a bug and it would be of interest here. I did not see a duplicate while searching GitHub.
First my code:
import pandas as pd
import plotly.express as px
stages = ["Initial Landing", "Step 2", "Step 3", "Added to cart", "Purchased"]
regiona_plotly = pd.DataFrame(dict(number=[10866,10543,1067,1032,108], stage=stages))
regionb_plotly = pd.DataFrame(dict(number=[10650,10432,1076,1036,1012], stage=stages))
regiona_plotly['region'] = "Region A"
regionb_plotly['region'] = "Region B"
df = pd.concat([regiona_plotly, regionb_plotly], axis=0)
fig = px.funnel(df, x='number', y='stage', color='region')
fig.update_traces(textposition='auto')
fig.update_layout(autosize=True)
fig.write_image("region_funnel.png")
(Lifted almost entirely from plotly documents)
This code produces an image like so:

Notice that on "Step 3", "Added to cart", and "Purchased" the region A text is scaled very small and inside the bar, but Region B is outside.
I tried updating this line:
fig.update_traces(textposition='outside')
But, with this, I get both values overlapping on the Region B side of the funnel. Also, the text goes outside of the plot on the upper bands.
How can I get text to be the same size and either be within the bar if it fits at the size or outside and on the correct side, if it doesn't?
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先,使用提供的 pandas、plotly.express、update_traces(textposition='auto') 和 write_image 示例复现堆叠漏斗图。跟踪漏斗文本定位在较小阶段如何处理 Region A 和 Region B 标签;完成的标准是标签保持一致且易读的大小,位于正确的一侧,并且不会重叠或移出绘图区域。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, python
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100
