i have something strange in my opinion. I have a dataframe with 3 columns. I created a stacked bar, but not all values are shown in my stacked-bar graphic.
This is my code:
#Create STACKED bar
data3 = data.groupby(['Bouwnummer', 'Omschrijving klachttype']).size().to_frame('Aantal klachten')
data3.reset_index(inplace=True)
st.dataframe(data = data3)
chart2 = alt.Chart(data3).mark_bar().encode(
x='Bouwnummer',
y='Aantal klachten',
color='Omschrijving klachttype'
).interactive()
# Show the chart2
st.altair_chart(chart2, use_container_width=True)
My dataframe shown with streamlit
Stacked bar in streamlit not showing all values of 'Bouwnummer 63'
Why are not all values of 'Bouwnummer 63' shown in the graph?
Thnx in advanced
CodePudding user response:
If you want the bars to be stacked, you can specify this in the stack
argument of the y
encoding:
chart2 = alt.Chart(data3).mark_bar().encode(
x='Bouwnummer',
y=alt.Y('Aantal klachten', stack=True),
color='Omschrijving klachttype'
).interactive()
Alternatively, if you ensure that the x
encoding is ordinal rather than quantitative, the bars will be stacked by default:
chart2 = alt.Chart(data3).mark_bar().encode(
x='Bouwnummer:O',
y='Aantal klachten',
color='Omschrijving klachttype'
).interactive()