altair - 将刻度线与条形图中的条形中心对齐

时间:2021-03-20 18:34:00

标签: bar-chart altair

如何在条形图的条形中间居中刻度线?

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 个答案:

答案 0 :(得分:3)

'yearmonth(Time_Received):T' 更改为 'yearmonth(Time_Received):O':这将使其成为序数(即有序分类)编码,并且标签将默认出现在每个类别的中心。