Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommended way to move headers to the bottom of subplots for grouped bar charts

I am trying to make a chart like the following in VL/Altair:

enter image description here

In this example, the X axis labels function like VL headers as far as I can tell. In VL/Altair, the headers are automatically set to the top of each subplot (e.g., this chart).

What is the recommended way of creating a grouped bar chart like this where the headers are located at the bottom?

If I work from this VL example, I can use "labelPadding" to move the headers down below but would like to know if there is a better way of accomplishing this without hard coded values (I've tried other options from the header docs but it seems that headers really prefer to be above the subplots, unless I've missed something):

"column": {"type": "nominal", "field": "site", "header": {"labelPadding": -320}}
like image 684
campo Avatar asked Oct 14 '25 14:10

campo


1 Answers

You can set the location of the header title and labels using labelOrient and titleOrient properties of the column's header.

Modifying the grouped bar chart example you linked to, it might look something like this:

import altair as alt
from vega_datasets import data

source = data.barley()

alt.Chart(source).mark_bar().encode(
    x=alt.X('year:O',
        axis=alt.Axis(title=None, labels=False)),
    y='sum(yield):Q',
    color='year:N',
    column=alt.Column('site:N',
        header=alt.Header(titleOrient='bottom', labelOrient='bottom'))
)

enter image description here

like image 82
jakevdp Avatar answered Oct 19 '25 14:10

jakevdp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!