plotly / plotly/plotly.py

Add continuous color scale to strip, box, and violin plots

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

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

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

説明

Currently, strip/box/violin plots only work with categorical/discrete colormaps. This is sufficient for the violins and boxes but for the points that can be included in all three plots, it would be useful to color by a continuous feature and to add a colorbar to the plot. I looked around a bit and it seems like the go.Box constructor needs to have the coloraxis attrbute added to it (and I suspect something would need to be added to avoid coloring the boxes/violins in the same colors as the points, since they are colored the same for categorical variables).

The example below illustrates the issue by trying to color by the sepal_width variable:

import plotly.express as px

iris = px.data.iris()
px.strip(iris, 'species', 'sepal_length', 'sepal_width', stripmode='overlay')

image

The resulting plot is not meaningful since it colors a continuous variable with a discrete colormap.

So far, I have not found a prettier workaround that this (which is imperfect since it uses the legend instead of a colorbar):

import matplotlib as mpl

sw = iris['sepal_width'].sort_values()
sw_01 = (sw - sw.min()) / (sw.max() - sw.min())
sw_colors = {n: mpl.colors.rgb2hex(c) for n, c in zip(sw, mpl.cm.viridis(sw_01))}
px.strip(iris, 'species', 'sepal_length', 'sepal_width',
         stripmode='overlay', category_orders={'sepal_width': sw.to_list()[::-1]},
         color_discrete_map=sw_colors)

image

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

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

はじめの一歩

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

調査の方向性

px.strip と go.Box コンストラクターから始め、strip、box、violin プロットが現在どのようにカテゴリカルな色を扱っているかに焦点を当てます。sepal_width を色の特徴量として使用して iris の例を再現し、次に coloraxis 属性とプロットの colorbar がどのように組み立てられるかを追跡します。含まれているポイントに対して連続的な色付けと colorbar が機能し、ポイントの色が box や violin に誤って適用されなければ完了です。

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

評価

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

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

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