Funnel plot text does not position itself properly
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 18.3k
- フォーク
- 2k
- 平均マージ
- 2日 12時間
- マージ済み PR(30日)
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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
