altair
altair copied to clipboard
Boxplot not working with MarkDef
Hi,
I noticed that specifying a boxplot through MarkDef doesn't work, even though the docs state it should. Tested with Altair 4.2.0 and 4.1.0. Using mark_boxplot
works OK for me.
Example:
import pandas as pd
df = pd.DataFrame({
'foo': [1,1,2,2,2,2,3,4,4,5]
})
# works
import altair as alt
alt.Chart(df).mark_boxplot().encode(y='foo')
# fails
import altair as alt
alt.Chart(df, mark=alt.MarkDef(type='boxplot')).encode(y='foo')
This fails with
SchemaValidationError: Invalid specification
altair.vegalite.v4.schema.core.MarkDef->type, validating 'enum'
'boxplot' is not one of ['arc', 'area', 'bar', 'image', 'line', 'point', 'rect', 'rule', 'text', 'tick', 'trail', 'circle', 'square', 'geoshape']
Can you point to the incorrect documentation?
The generated docs from vega-lite https://altair-viz.github.io/user_guide/generated/core/altair.MarkDef.html say:
This could a primitive mark type (one of "bar", "circle", "square", "tick", "line", "area", "point", "geoshape", "rule", and "text" ) or a composite mark type ( "boxplot", "errorband", "errorbar" )"
Since a boxplot
is a composite mark, you would need to use:
alt.Chart(df, mark=alt.CompositeMarkDef(type='boxplot')).encode(y='foo')
The docs for this are being updated in https://github.com/altair-viz/altair/pull/3266/files