Hi,
I’m looking to use the bandPosition=0 parameter in my altair bar-graphs, but it doesn’t seem to have any effect, is there something I’m doing wrong?
I’m on python 3.12.0, running streamlit locally.
Streamlit v1.32.2 uses Altair 5.2.0 which in turn has Vega-Lite 5.16.3 which is greater than: 5.16.0 · vega/vega-lite (github.com)
Which has " bandPosition=0
/ Center aligned (new)".
So in a jupyter notebook it can look like this:
import altair as alt
import pandas as pd
import numpy as np
# Sample data
np.random.seed(0)
data = pd.DataFrame({
'Date': pd.date_range('2021-01-01', periods=4, freq='D'),
'Value': np.random.rand(4)
})
# Vega-Lite chart with bandPosition
chart = alt.Chart(data).mark_bar().encode(
x=alt.X('yearmonthdate(Date):T', bandPosition=0.0),
y=alt.Y('Value:Q', axis=alt.Axis(title='Value'))
)
chart
Note the very nice looking labels for the bars
In streamlit ive tried both altair_chart and directly with st.vega_lite_chart(). Here is the regular altair_chart version.
np.random.seed(0)
data = pd.DataFrame({
'Date': pd.date_range('2021-01-01', periods=4, freq='D'),
'Value': np.random.rand(4)
})
# Vega-Lite chart with bandPosition
chart = alt.Chart(data).mark_bar().encode(
x=alt.X('yearmonthdate(Date):T', bandPosition=0.0),
y=alt.Y('Value:Q', axis=alt.Axis(title='Value'))
)
st.altair_chart(chart)
Changing bandPosition doesnt do anything here and the result is not like raw altair in the notebook.
Hope you could lend me a hand in figuring this out, or if I need to file a bug report.
/Alexander