Altair figure height can't fit properly within the column

Summary

Hi!
The Altair chart height cannot fit properly within the column, and the coordinates are cut off.
I have tried to adjust figure size via Altair library,but still faild.

Here is my code.

Code snippet:

            ho_data = pd.melt(flight_df.T.fillna(
                0).reset_index(), id_vars=["index"])
            chart = (
                alt.Chart(ho_data)
                .mark_bar()
                .encode(
                    x=alt.X("value", type="quantitative", title=""),
                    y=alt.Y("index", type="nominal", title=""),
                    color=alt.Color("variable", type="nominal", title=""),
                    order=alt.Order("variable", sort="descending"),
                )
                .properties(
                    # width='container',
                    height=450
                ))

            st.altair_chart(chart, use_container_width=True, theme='streamlit')

Expected behavior:

coordinates shouldn’t be cut off when the figure height changed.

I wonder know how can I “fit” the custom Altair figure size in a column(especially changed height)
Thank you!

import altair as alt
import pandas as pd
import streamlit as st
flight_df = pd.DataFrame({
    "index": ["A", "B", "C", "D"],
    "variable1": [100, 150, 200, 250],
    "variable2": [50, 75, 100, 125],
    "variable3": [30, 45, 60, 75],
    "variable4": [70, 105, 140, 175]
})
ho_data = pd.melt(flight_df.T.fillna(0).reset_index(), id_vars=["index"])
chart = (
    alt.Chart(ho_data)
    .mark_bar()
    .encode(
        x=alt.X("value", type="quantitative", title=""),
        y=alt.Y("index", type="nominal", title=""),
        color=alt.Color("variable", type="nominal", title=""),
        order=alt.Order("variable", sort="descending"),
    )
    .properties(width=alt.Step(20),height=alt.Step(80),)
)
st.altair_chart(chart, use_container_width=True, theme='streamlit')

Instead of directly giving height[its cutting some text] am introducing step function
when you use step function you wont face such issue

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.