altair icon indicating copy to clipboard operation
altair copied to clipboard

Boxplot not working with MarkDef

Open eeroel opened this issue 3 years ago • 2 comments

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']

eeroel avatar Jan 09 '22 08:01 eeroel

Can you point to the incorrect documentation?

jakevdp avatar Jan 09 '22 13:01 jakevdp

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" )"

eeroel avatar Jan 09 '22 15:01 eeroel

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

joelostblom avatar Mar 16 '24 16:03 joelostblom