plotly / plotly/plotly.py

Bar ordering is inconsistent

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

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

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

説明

Plotly 5.15.0
Python 3.11

When creating a stacked bar chart with a sorted dataframe the order of bars is inconsistent. In some cases I get the desired result sorted by total bar length and in other cases I get what appears to be sorted by category.

For example, the following sorted dataframe is charted with the expected bar order:

   index        name category  value  total
0      2  rnlblpykns     cat1     75    173
1      4  rnlblpykns     cat3     66    173
2      1  rnlblpykns     cat0     26    173
3      3  rnlblpykns     cat2      6    173
4      8  lfqlfxlpxt     cat1     77     86
5      7  lfqlfxlpxt     cat0      9     86
6      5  axnqvjlmql     cat0     46     54
7      6  axnqvjlmql     cat1      8     54
8      0  zfbcsrusbq     cat0     18     18

correct

While the chart for the following sorted dataframe appears to be ordered by 'name':

    index        name category  value  total
0       4  tprmmexxdf     cat4     96    307
1       1  tprmmexxdf     cat1     89    307
2       0  tprmmexxdf     cat0     58    307
3       2  tprmmexxdf     cat2     54    307
4       3  tprmmexxdf     cat3     10    307
5      10  iontrwxbjg     cat0     91    271
6      11  iontrwxbjg     cat1     86    271
7      13  iontrwxbjg     cat3     46    271
8      14  iontrwxbjg     cat4     37    271
9      12  iontrwxbjg     cat2     11    271
10      7  ffxalebxgi     cat2     57    234
11      8  ffxalebxgi     cat3     48    234
12      5  ffxalebxgi     cat0     44    234
13      9  ffxalebxgi     cat4     44    234
14      6  ffxalebxgi     cat1     41    234
15     16  bzbaayrcra     cat1     78    146
16     15  bzbaayrcra     cat0     55    146
17     18  bzbaayrcra     cat3      8    146
18     17  bzbaayrcra     cat2      5    146
19     20  ejehjurxge     cat1     50    132
20     22  ejehjurxge     cat3     39    132
21     23  ejehjurxge     cat4     22    132
22     21  ejehjurxge     cat2     15    132
23     19  ejehjurxge     cat0      6    132

image

The code is as follows:

import random
import string

import plotly.express as px
import pandas as pd


def random_dataframe():
    names = []
    categories = []
    values = []
    for i in range(random.randint(3, 6)):
        letters = string.ascii_lowercase
        name = ''.join(random.choice(letters) for i in range(10))
        for j in range(random.randint(1, 5)):
            names.append(name)
            categories.append(f"cat{j}")
            values.append(random.randint(1, 100))

    df = pd.DataFrame({
        "name": names,
        "category": categories,
        "value": values
    })

    return df


df = random_dataframe()
df["total"] = df.groupby("name")["value"].transform(sum)
df = df.sort_values(by=["total", "name", "value"], ascending=False).reset_index()

print(df)

fig = px.bar(
    df,
    x="value",
    y="name",
    orientation="h",
    color="category",
    width=640,
    height=480
)

fig.show()

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

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

はじめの一歩

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

調査の方向性

提供された Python 3.11 の例を Plotly Express px.bar で実行し、2 つの dataframe ケースを比較します。グループ化された name、category、value 列からバーの順序がどのように導出されるかを調査します。同等にソートされたデータで一貫した、文書化されたバーの順序が得られ、その動作が回帰テストでカバーされれば完了です。

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

評価

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

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

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