matplotlib / matplotlib/mpl-altair

Add aggregate support

Open
#32 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
18
Forks
7
PR merge metrics
No merged PRs in 30d

Description

mpl-altair currently doesn't support conversion for Altair charts that use aggregations.

**Code for reproduction**

data:
```python
df = pd.DataFrame({
'a': [1, 1, 2, 3],
'b': [1.1, 2.2, 3.3, 4.4]
})
```
Example 1:
```python
chart = alt.Chart(df).mark_point().encode(
alt.X('a'), alt.Y('average(b)')
)
mplaltair.convert(chart)
```
Example 2:
```python
chart = alt.Chart(df).mark_point().encode(
alt.X('a'), alt.Y('count()')
)
mplaltair.convert(chart)
```

**Actual outcome**

A `NotImplementedError` is raised for anything that has aggregated data.

**Expected outcome**

Any plot with [aggregation](https://altair-viz.github.io/user_guide/encoding.html#binning-and-aggregation) should work.

The first chart should look something like this:

![aggregates_altair](https://user-images.githubusercontent.com/9091763/44239097-365f4f80-a17d-11e8-9462-c6b8f010c841.png)

The second chart should look something like this:

![aggregates_altair_count](https://user-images.githubusercontent.com/9091763/44239106-3bbc9a00-a17d-11e8-8f81-8cf42722db6a.png)

**Possible solution**

During the initial altair chart parsing, manipulate the data to include the aggregations. See `parse_chart.ChannelMetadata()` (specifically `_aggregate_channel()`).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in parse_chart.ChannelMetadata(), particularly _aggregate_channel(), and reproduce the issue with the two Python chart examples using average(b) and count(). Trace how aggregated data is parsed and ensure both mplaltair.convert(chart) calls complete without NotImplementedError and produce the expected aggregate plots.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.