plotly / plotly/plotly.py

customdata parsed incorrectly when array contains more than 1 column in piechart

オープン
#5,191 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug P2
主要言語
Python
スター
18.8k
フォーク
2.8k
平均マージ
16時間 26分
マージ済み PR(30日)
21

説明

When using more than one column to define customdata, the data seems to be parsed as a tuple.
The example below shows three versions of the same figure:

  • LEFT. Only one column of customdata. Works as expected.
  • CENTER. Two columns of customdata. The first column in customdata is not parsed correctly when using a :.1s format. The second column in customdata is not parsed correctly by hovertemplate in go.Pie but is parsed correctly by texttemplate.
  • RIGHT. Workaround using customdata as a tuple and selecting its first %{customdata[0][0]} and second %{customdata[0][1]} values accordingly.
import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots

df = pd.DataFrame({
    'country': ['A', 'B', 'C'],
    'count':   [10, 20, 30],
    'total': [1.5e5, 4.5e4, 3.2e3],
    'ratio': [0.05, 0.10, 0.15]
})

fig = make_subplots(rows=1, cols=3, specs=[[{"type": "domain"}, {"type": "domain"}, {"type": "domain"}]])

# customdata parsed correctly with only one column
fig.add_trace(go.Pie(
    labels=df['country'],
    values=df['count'],
    customdata=df[['total']], # 1 column
    hovertemplate=(
        'Country: %{label}<br>'
        'Count: %{value}<br>'
        'Total documents: %{customdata[0]:.1s}'),
    hole=0.3
),
row=1, col=1)

# Problem with customdata
fig.add_trace(go.Pie(
    labels=df['country'],
    values=df['count'],
    customdata=df[['total', 'ratio']], # >1 columns
    hovertemplate=(
        'Country: %{label}<br>'
        'Count: %{value}<br>'
        'Total documents: %{customdata[0]:.1s}<br>'
        'Ratio: %{customdata[1]:.2f}'),
    texttemplate = "%{customdata[1]:.2p}", # correctly parsed
    hole=0.3
),
row=1, col=2)

# Workaround
fig.add_trace(go.Pie(
    labels=df['country'],
    values=df['count'],
    customdata=df[['total', 'ratio']], # >1 columns
    hovertemplate=(
        'Country: %{label}<br>'
        'Count: %{value}<br>'
        'Total documents: %{customdata[0][0]:.1s}<br>' # as tuple
        'Ratio: %{customdata[0][1]:.2f}'),
    texttemplate = "%{customdata[1]:.2p}",  # correctly parsed
    hole=0.3
),
row=1, col=3)

fig.show()

Tested using:
Plotly.py: 6.0.1
Pandas: 2.1.4

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、提供されている Plotly.py と Pandas の再現コードを実行し、次に複数列の customdata が pie-chart の hovertemplate フォーマットにどのように渡されるかを追跡します。完了条件は、tuple-style indexing を使わずに両方の customdata 列が要求された形式で表示され、1 列の場合と texttemplate の動作も正しいままであることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
pandas, python
領域
data-visualization
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。