h2oai / h2oai/wave

Respect Order of Color Domain in the Plot Key

Open
#1,269 2 comments 0 reactions 0 assignees View on GitHub
feature plot
Dominant language
Python
Stars
4.3k
Forks
371
Avg merge
26d 1h
Merged PRs (30d)
1

Description

#### Is your feature request related to a problem? Please describe
In the below example you can see that the order of the `color_range` and `color_domain` categories are such that `A` is blue and `B` is red. ~However, colors from the `color_range` list are assigned to the values of the `color` column based on the order that they appear in the data object.~ Our key the fields are in the "wrong" order ~and the categories don't have the colors we would expect.~

```python
# Plot two numeric columns by each other and color based on a third, categorical column
q.page['scatter'] = ui.plot_card(
box='1 1 4 5',
title='Scatter Plot from Dataframe',
data=data(
fields=["x_value", "y_value", "category"],
rows=[
[10, 100, 'B'],
[100, 10, 'A'],
[99, 67, 'B'],
],
pack=True,
),
plot=ui.plot(marks=[ui.mark(
type='point',
x='=x_value', x_title='My X Value',
y='=y_value', y_title='My Y Value',
color='=category', shape='circle', color_range="blue red", color_domain=["A", "B"]
)])
)
```
![image](https://user-images.githubusercontent.com/4793561/155635118-4487f9fe-355a-4ca6-8cf3-c6c27bb334d2.png)

#### Describe the solution you'd like
The `color_range` and `color_domain` features to be considered a "mapping" with a respected order, which is happening the color assignment, however the key is ordered based on when the data appears.

#### Describe alternatives you've considered
Require the user to order their data appropriately. If we go with this we should add more documentation around it, and explicitly add a plot example that uses `color_domain`

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the Python plot_card example with color_domain=["A", "B"] and rows whose first category is "B". Trace the plot key and color assignment handling to find where category order is chosen. Done means the key follows color_domain order while preserving the corresponding color_range mapping.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.