-
Notifications
You must be signed in to change notification settings - Fork 795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Date x-axis is shifted by -1 day #2540
Comments
This is a timezone/date parsing issue in Javascript. You need your date strings to be fully-qualified ISO 8601 date strings, or Javascript will parse them as UTC rather than local time. If you use a pandas dataframe and ensure that your column is a datetime type, Altair will take care of the details for you. See e.g. vega/vega-lite#6883 for details. |
Thanks for the swift response. I'm really glad you shared this issue with me because I wouldn't have found it otherwise. Do you think this is worth adding to the docs? |
Yeah, it might be worth adding this in a FAQ or a "gotchas" page. |
Here's a similar issue in the Altair repo: #2077 |
I tried casting the column to datetime and set utc=True. Still getting that weird -1 day behaviour in the plots.
Am I doing this right? I'm not familiar with ISO8601 strings so let me know if I'm doing this wrong. |
You probably don't want (also, just in case this is an area of confusion: |
I encountered a similar off by one issue on SO the other day and I think that one was timezone related and will be fixed when this vegalite issue is closed vega/vega-lite#7795 |
Thanks for sharing this! looks like this PR is still waiting for reviewers. Unfortunately I don't have the context to review this particular PR but hopefully it gets shipped soon Any work-arounds that you've used in the meantime @joelostblom? |
I'm not sure on the top of my head, but you could try writing your dates as |
@topspinj I just posted a possible workaround in this SO answer that you can try https://stackoverflow.com/a/71685940/2166823 |
The corresponding Vega-Lite issues have now been merged and this appears fixed to me when trying with the SO example I linked above, so closing this. Please reopen with a spec that is not working in altair 5 if there are still issues. |
I've been using Altair within Streamlit and have been enjoying it for the most part. However, I noticed that Altair behaves oddly when I create plots where the x-axis is a date field.
the min date is Sept 1, 2021 but when I hover over the Altair chart, it says Aug 31, 2021 🤔
I haven't reproduced this in Jupyter notebooks yet but I do see this strange behaviour consistently in the context of Streamlit. Anyone else experience this issue?
The text was updated successfully, but these errors were encountered: