【问题标题】:altair - aligning tick marks with center of bars in bar plotaltair - 将刻度线与条形图中的条形中心对齐
【发布时间】:2021-03-21 05:52:03
【问题描述】:

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

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
)
   

【问题讨论】:

    标签: bar-chart altair


    【解决方案1】:

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

    【讨论】:

    • 杰克:非常感谢!
    • 您的建议效果很好。 OOTH,是否可以更改 x 轴刻度标签的频率,以防在某些用例中可能是首选?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多