plotly / plotly/plotly.py

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

Đang mở
#1,938 22 bình luận 6 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

feature P3
Ngôn ngữ chính
Python
Star
18.8k
Fork
2.8k
Merge trung bình
16 giờ 26 phút
Pull request đã merge (30 ngày)
21

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với px.strip và hàm khởi tạo go.Box, tập trung vào cách các biểu đồ strip, box và violin hiện xử lý màu phân loại. Tái tạo ví dụ iris bằng cách sử dụng sepal_width làm đặc trưng màu, sau đó theo dõi cách thuộc tính coloraxis và colorbar của biểu đồ được tạo ra. Hoàn thành khi việc tô màu liên tục và một colorbar hoạt động cho các điểm được đưa vào mà không áp dụng sai màu của các điểm cho các box hoặc violin.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
data-visualization
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.