altair - aligning tick marks with center of bars in bar plot

Viewed 470

How do I center tick marks in the middle of the bars of a bar chart?

enter image description here

title = 'Submissions from Aug 2018 to Feb 2020 by Month'
chart = alt.Chart(df_US).mark_bar(size = 25,
         color = 'black').encode(
    x=alt.X('yearmonth(Time_Received):T',
            axis =alt.Axis(format = "%b%y", 
                           tickCount = 20,
                           tickBand = 'center')),
    y='count(Time_Received)'
).configure_axisX(  tickBand = 'center'
).properties(
    width = 900,
    title  = title
).configure_axis(
    grid=False
)
   
1 Answers

Change 'yearmonth(Time_Received):T' to 'yearmonth(Time_Received):O': this will make it an ordinal (i.e. ordered categorical) encoding, and the labels will appear by default at the center of each category.

Related