Home > Net >  Altair SchemaValidation Error When Faceting
Altair SchemaValidation Error When Faceting

Time:12-01

I have this dataframe:

df

And I want to make a horizontal stacked bar chart that displays the same information as this chart:

chart

I have generated this code:

chart = alt.Chart(df_q4).mark_bar().encode(
    x = alt.X('value:Q', axis=None),
    color=alt.Color('color_code:N', scale=None),
    ).facet("title:N"
    ).properties(
    width=400,
    height=700)
    
    
chart

However it throws this error:

SchemaValidationError: Invalid specification

        altair.vegalite.v4.api.Chart, validating 'required'

        'data' is a required property
        

alt.FacetChart(...)

I am not sure why I cannot facet. I have also tried encoding the facet object within the chart encoding, and that did not work as well.

I also would like to incorporate some code into my chart that shows only the titles, colors, and values pertaining to a specific season. This will be via wrapping the code within a function that's something like:

define color_palette(season):

CodePudding user response:

Facet charts do not support width or height properties. Perhaps you meant this?

chart = alt.Chart(df_q4).mark_bar().encode(
    x = alt.X('value:Q', axis=None),
    color=alt.Color('color_code:N', scale=None),
).properties(
    width=400,
    height=700
).facet(
    "title:N"
)
  • Related