简体   繁体   English

我如何在 Altair 中使用 label 日期轴,每周都有刻度?

[英]How do I label a date axis in Altair with ticks every week?

It looks like Vega allows you to specify both resolution (eg day) and interval for date/time axes: https://vega.github.io/vega-lite/docs/axis.html#labels看起来 Vega 允许您为日期/时间轴指定分辨率(例如天)和间隔: https://vega.github.io/vega-lite/docs/axis.html#labels

{"interval": "month", "step": 3}

But when I try to specify alt.Axis(formatType="time", tickCount=alt.TickCount('day', step=7) , for example, I get an invalid schema error.但是,例如,当我尝试指定alt.Axis(formatType="time", tickCount=alt.TickCount('day', step=7)时,我得到一个无效的架构错误。

Is there a way to specify that I want date ticks every 7 days (ie weekly dates, not week number)?有没有办法指定我希望每 7 天打一次日期(即每周日期,而不是周数)?

Turns out there's a way to do this (sort of), which is to set the nice parameter in the alt.Scale , not in the axis as with Vega.原来有一种方法可以做到这一点(有点),即在alt.Scale中设置nice参数,而不是像 Vega 那样在轴上。 So:所以:

alt.Scale(nice={'interval': 'day', 'step': 7})

The problem is it seems to then round to nice values;问题是它似乎会四舍五入到不错的值; so it won't start on the first day of data, but say the first of that day's month.所以它不会从数据的第一天开始,而是说当月的第一天。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM