plotly / plotly/plotly.py

set categoryarray=None for that axis when matches=None

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

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

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

説明

Current behaviour
When a plot is created with facetted rows and xaxes matches is set to None, in the bottom plot the ticklabels for the values that are in other rows are still visible.

import plotly.express as px
import plotly
df = plotly.data.election()
fig = px.scatter(df, x= 'winner', y='total', facet_row="winner")
fig.for_each_xaxis(lambda x: x.update(showticklabels=True, matches=None))
fig.show()

image

  • When a facetted figure is created, the items regarding xaxes of the resulting fig.layout look like this:
    'xaxis': {'anchor': 'y',
              'categoryarray': [Joly, Coderre, Bergeron],
              'categoryorder': 'array',
              'domain': [0.0, 0.98],
              'title': {'text': 'winner'}},
    'xaxis2': {'anchor': 'y2', 'domain': [0.0, 0.98], 'matches': 'x', 'showticklabels': False},
    'xaxis3': {'anchor': 'y3', 'domain': [0.0, 0.98], 'matches': 'x', 'showticklabels': False},
  • xaxis2 and xaxis3 refer to the two top rows, while xaxis refers to the bottom one. The main difference between the two groups is that xaxis has some additional items/properties: 'categoryarray': [Joly, Coderre, Bergeron], 'categoryorder': 'array', 'title': {'text': 'winner'}
  • When we apply fig.for_each_xaxis(lambda x: x.update(showticklabels=True, matches=None)), the same part of fig.layout gets updated to:
    'xaxis': {'anchor': 'y',
              'categoryarray': [Joly, Coderre, Bergeron],
              'categoryorder': 'array',
              'domain': [0.0, 0.98],
              'showticklabels': True,
              'title': {'text': 'winner'}},
    'xaxis2': {'anchor': 'y2', 'domain': [0.0, 0.98], 'showticklabels': True},
    'xaxis3': {'anchor': 'y3', 'domain': [0.0, 0.98], 'showticklabels': True},
  • The categoryarray and categoryorder elements are still there (with the values for the three facets, not only the bottom one), so we need to remove them, which we can do with:
fig.for_each_xaxis(lambda x: x.update(categoryorder=None, categoryarray=None))

or

fig.update_xaxes(categoryarray=None, selector={'anchor':'y'})
  • The updated part of the dict is:
    'xaxis': {'anchor': 'y', 'domain': [0.0, 0.98], 'showticklabels': True, 'title': {'text': 'winner'}},
    'xaxis2': {'anchor': 'y2', 'domain': [0.0, 0.98], 'showticklabels': True},
    'xaxis3': {'anchor': 'y3', 'domain': [0.0, 0.98], 'showticklabels': True},

Desired behaviour

  • When a plot is created with facetted rows and xaxes matches is set to None, categoryorder should be set to None for those axes.
  • If the categoryorder has been specified on plot creation, that order is respected even after setting categoryorder to None. It would only be changed if we set a new value for that argument:
import plotly.express as px
df = px.data.tips()
df['weekend'] = df['day'].apply(lambda x: "weekend" if x in ["Sat", "Sun"] else "weekday")
fig = px.bar(df, x="day", y="total_bill", color="smoker", barmode="group", facet_row="weekend",
             category_orders={
                 "weekend":["weekday", "weekend"],
                 "day": ["Thur", "Fri", "Sat", "Sun"],
                 "smoker": ["Yes", "No"],
                 "sex": ["Male", "Female"]
                 })
fig.for_each_xaxis(lambda x: x.update(showticklabels=True, matches=None))
fig.update_xaxes(categoryarray=None, selector={'anchor':'y'})
fig.show()

plot_20sep

fig.update_xaxes(categoryarray=["Sun", "Sat"], selector={'anchor':'y'})

plot_20sep_2

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

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

はじめの一歩

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

調査の方向性

提供されている Plotly Express のファセット行の再現例から始め、matches=None を設定する前後で生成される xaxis、xaxis2、xaxis3 の layout オブジェクトを調べます。categoryarray と categoryorder をクリアすると、明示的な category_orders 設定を維持したまま、ファセット全体のカテゴリ値が削除されることを確認し、示されている例で結果の軸レイアウトを確認します。

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

評価

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

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

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