When plotting timeseries data with altair, the timezone appears to be converted from UTC into the browser locale. The underlying data does not contain any timezone information. When an equivalent plot is created in a jupyter notebook, it correctly displays the time as-is, without adjustment.
Steps to reproduce
Run the following and note the difference between the dataframe and the plot (assuming you are not in a UTC+0 timezone)
Code snippet:
import altair as alt
import streamlit as st
import pandas as pd
df = pd.DataFrame({
'datetime': [pd.to_datetime('2023-06-01 12:00')],
'value': [10],
})
df
st.altair_chart(
alt.Chart(df).mark_bar().encode(
x='datetime', y='value')
)
Expected behavior:
The plot should display the time without timezone adjustment.
Actual behavior:
The plot shows the datetime adjusted to my timezone, incorrectly assuming the underlying data is UTC.
Debug info
Streamlit version: Streamlit, version 1.23.1
Python version: Python 3.10.8
OS version: windows 10 20H2 19042.2965
Browser version: Chrome canary 116.0.5813.0 or Edge 114.0.1823.37
A standard timezone-agnostic date/time column in a Pandas dataframe will be both interpreted and displayed as local user time
Streamlit appears to be interpreting the datetime in UTC+0 and displaying in local time. If I use altair directly to plot or save the chart to JSON, there is no timezone conversion.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.