Time axis with custom scale

Hi
I’m trying to set custom scales to a time axis in an altair chart. It used to work fine, until I updated to streamlit version 1.15.0

import streamlit as st
import pandas as pd
import altair as alt
from vega_datasets import data

temps = data.seattle_temps()
temps = temps[ temps.date.dt.hour == 10 ]

startDate = pd.to_datetime("2010-06-01")
endDate = pd.to_datetime("2010-06-30")
myScale = alt.Scale(domain=[startDate, endDate], )

c = alt.Chart(temps).mark_line(clip=True).encode(
    x=alt.X('date:T', scale=myScale),
    y='temp:Q'
)

st.altair_chart( c )

c.show()

output in streamlit (st.altair_chart( c ) )

2022-11-18 14_46_02-AxisBug_Streamlit · Streamlit — Mozilla Firefox

output in altair viewer ( c.show() )

2022-11-18 14_46_32-Altair Viewer — Mozilla Firefox

In streamlit the axis is not correct.

Hi @xavierc, thanks for posting in the forum! I believe this is a bug – you’ve pointed out correctly (and I’ve verified) that this works in Streamlit 1.13 but not in >=1.14. I’ve filed a bug here and you can follow as it gets resolved.

Thanks

Hey @xavierc, I wanted to follow up on this – it turns out that this is a bug in Altair – not Streamlit specifically. I gave it a spin in a jupyter notebook and a colab notebook (removing any Streamlit code) and the chart is also blank there. I encourage you to give it a try. We are going to file a bug for Altair and hopefully, they can fix it!

1 Like

Hi @TylerS, do you have a minimal example reproducing the Altair bug?/Altair bug report yet? I’m a little confused how a Streamlit version change exposed an Altair regression. Does Streamlit use a pinned Altair version and did they increment it?

Hi @tsand yep – I was confused too. Here’s the code and a picture.


I think Streamlit changed how they evaluate Altair calls with the upgrade to 1.14.

import altair as alt
import pandas as pd
from vega_datasets import data
import datetime

temps = data.seattle_temps()
temps = temps[temps.date.dt.hour == 10]

startDate = pd.to_datetime("2010-06-01")
endDate =  pd.to_datetime("2010-06-30")
myScale = alt.Scale(domain=[startDate, endDate])

c = (alt.Chart(temps)
    .mark_line(clip=True)
    .encode(x=alt.X("temp:T", scale=myScale), y="temp:Q"))

c```