Open
Description
mpl-altair currently doesn't support conversion for Altair charts that use binning.
Code for reproduction
from vega_datasets import data
seattle = data.seattle_weather()
seattle.head()
Binning color in a scatter plot:
chart = alt.Chart(seattle).mark_point().encode(
alt.X('wind'), alt.Y('temp_max'), alt.Color('temp_min', bin=alt.Bin(step=10))
)
mplaltair.convert(chart)
Binning in a bar chart:
chart = alt.Chart(seattle).mark_bar().encode(
alt.X('wind', bin=True), alt.Y('count()')
)
mplaltair.convert(chart)
Actual outcome
In a chart that would work without binning, binning fails silently and the chart is converted as if binning is always false.
Binning color in a scatter plot:
Binning in a bar chart:
raises NotImplementedError
until bar charts and aggregates are working.
Expected outcome
Converting a scatter plot with binned color should produce a chart that looks something like this:
Converting a binned bar chart should produce a chart that looks something like this:
Possible solution and notes
- Manipulate the data to be binned in
parse_chart.ChannelMetadata()
. - Binning is probably better to add when bar charts and aggregate functions are functional in mplaltair.
- Be aware that binning can happen in the encoding definition or in a transform.
For more info
- Altair's user guide on binning
- Vega-Lite documentation on binning