bar chart: textposition='auto' not working for 0 values
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 18.3k
- フォーク
- 2k
- 平均マージ
- 2日 12時間
- マージ済み PR(30日)
- 28
説明

From the textposition argument documentation for bar traces:
"auto" tries to position
textinside the bar, but if the bar is too small and no bar is stacked on this one the text is moved outside.
For small values this is working nicely: Instead of inside, the text gets positioned outside.
But: For 0 values, the text disappears completely instead of being moved outside.
import pandas as pd
import plotly.express as px
df = pd.DataFrame({
"Country": [f"Country {n}" for n in range(6)],
"Some Metric": [8,5,5,.5,0.0001,0]
})
fig = px.bar(
df,
x='Some Metric',
y='Country',
text='Country',
orientation='h')
fig.update_yaxes(visible=False, showticklabels=False)
# change here between "auto" (default), "inside", "outisde"
fig.update_traces(textposition="auto")
fig.show()
Setting 0 values to a small value is a dirty fix that may also lead to the text disappearing when the graph is resized. At the same time, such a fix endangers data integrity.
The alternative would be setting the textposition for every observation separately. I think that should be avoided and covered by setting texposition="auto".
Fix that everybody can implement in their code currently:
fig.update_traces(textposition=['outside' if val==0 else 'auto' for val in df['Some Metric']])
Tested with plotly 5.10.0.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
textposition="auto" とゼロ値を使用した横棒グラフの例を再現し、その後、Plotly.js が使用する bar-trace のテキスト配置パスを追跡します。小さい値に対する既存の動作を確認し、値がゼロの場合にラベルがバーの外側に表示されたままになることを完了条件とし、可能であれば関連する bar-trace テストでカバレッジを追加します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript
- 領域
- data-visualization
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 活発
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 66/100