Search code examples
pythonpandasfacetaltair

Hiding facet row axis in Altair chart


I'm using a faceted chart in Altair in order to split a lengthy timeline into multiple rows.

My initial dataset is a pandas dataframe with "Start" and "End" timestamp columns and a "Product" string column.

I bin the dataset into roughly equal rows by evenly dividing the time range:

timestamp_normalized = (data.Start - data.Start[0]) / (data.Start.iloc[-1] - data.Start[0]) # range from 0 to 1
data['Row'] = (timestamp_normalized * 3 - 1e-9).astype(int) # divide into 3 bins

Then I draw the facet chart like this:

import altair as alt

alt.Chart(data).mark_bar().encode(
    x=alt.X('Start', title='')
    x2='End',
    color=alt.Color('Product', scale=alt.Scale(scheme='dark2'))
).properties(
    width=800,
    height=50
).facet(
    row=alt.Row('Row', title=''),
).resolve_scale(
    x='independent',
)

This produces the right chart, but unfortunately the bin indices (which are completely irrelevant, as they only serve to split it into three pieces) are shown on the left side. Is there any way to hide these?

enter image description here


Solution

  • To remove both the header title and labels you can use alt.Row('Row').header(None). You could also control them individually via alt.Row('Row').header(title=None, labels=False)

    For versions of Altair prior to 5: alt.Row('Row', header=alt.Header(title=None, labels=False))