h2oai / h2oai/wave

Align y-axis scales for plots with more than one mark type

Open
#1,292 1 comment 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

When plotting two different mark types on the same plot, the y-axis aren't guaranteed to be the same scale, even by setting the y_min / y_max consistently. One way to do this would be to introduce another parameter to control major tick interval.

Here's some example code:

```py
q.page['timeseries'] = ui.plot_card(box = ui.box('timeseries', height = '1000px'),
title = 'My Title',
data = ts_plot_data,
plot = ui.plot([
ui.mark(type='path', x_scale='time', x='=date', y='=picks', color='=label', y_min=0, y_max = np.max(plot_data["upper_bound"]), color_range="#3399FF #FF9966", y_title="Picks", y_nice=True),
ui.mark(type='area', x_scale='time', x='=date', y0='=lower_bound', y='=upper_bound', y_min=0, y_max = np.max(plot_data["upper_bound"]), y_nice = True)])
)
```

And the result:

![image](https://user-images.githubusercontent.com/2989937/157734066-f3e19a75-d04c-4d8c-9e98-0a7b77f4dadc.png)

in `ggplot2`, this is controlled explicitly with [sec_axis](https://ggplot2.tidyverse.org/reference/sec_axis.html). Ideally, if both marks are plotting the same quantity (or at least in the same units as each other), a secondary axis may not necessary. Here's another example using ggplot: https://www.r-graph-gallery.com/line-chart-dual-Y-axis-ggplot2.html

Contributor guide

Open the contributing guide

Research direction

Start with the Python plotting API demonstrated in the issue, especially ui.plot and ui.mark handling for path and area marks. Reproduce the example with shared y_min and y_max, then determine how major tick intervals or secondary-axis behavior should be specified. Done means multiple mark types plotting the same quantity use aligned y-axis scales, with the intended behavior covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.