Date axis labels are off by one
See original GitHub issueI have a time-series chart that I’d like to specify the tick labels for, but I can’t seem to get the right dates to show up. An MWE looks like this:
import altair as alt
import pandas as pd
axis_dates = ['2020-03-01', '2020-03-08', '2020-03-15', '2020-03-22', '2020-03-29', '2020-04-05']
df = pd.DataFrame({
'x': axis_dates,
'y': [1, 3, 5, 6, 4, 2]
})
alt.Chart(df).mark_line().encode(
x=alt.X('x:T', axis=alt.Axis(title='Date', format=("%b %d"), values=axis_dates)),
y='y')
How can I make the chart use the dates in the DataFrame? Thank you.
I am using 4.1.0.
EDIT: fixed my code
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Display or change dates on a category axis - Microsoft Support
In the chart, right-click the category axis, and then click Format Axis. · In the Format Axis pane, select the Axis Options tab....
Read more >Date Axis in Excel Chart is wrong - AuditExcel
You've built your chart, it all makes sense and suddenly you look at your horizontal axis, and the date axis is wrong. This...
Read more >Horizontal date axis incorrect on Excel line chart with ...
It turns out I accidentally keyed in a date that does not exist. ... (category) axis labels, if one of them is blank,...
Read more >Date axis labels in ggplot2 is one day behind - Stack Overflow
The dates in the data frame is May 1, May 2, and up to May 10, and the labels goes from April 30...
Read more >Excel axis shows wrong date- start of month or large gaps in ...
Date Axis in Excel Chart is wrong How to force Excel to use your typed in dates in a chart Although this feature...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The issue is you are not passing full ISO8601 strings, so some browsers parse them as UTC time, and then they are displayed in local time by Vega-Lite. This is why Altair always outputs full ISO strings (e.g.
2010-01-01T00:00:00
) which javascript always parses as local time. In general, the easiest way to deal with this is to always use pandas datetime type for time columns, then Altair takes care of the details for you.e.g.