Creating histogram for the distribution of values from one value to value in a

        if st.checkbox("Order data - Dimensions distribution column"):
            with st.form(key='my_form'):
                line1, line2, line3, line4 = st.columns(4)
                with line1:
                    length_name1 = st.text_input('Length', value="Length", help=None)
                    if length_name1 in df.columns:
                        pass
                    else:
                        st.write('entered text is not correct, please check the column headings')
                with line2:
                    min_length2 = st.number_input("Length minimum value ", value=1, step=1)
                with line3:
                    max_length3 = st.number_input("Length maximum value", value=1, step=1)
                with line4:
                    length_increment4 = st.number_input("Length increment value", value=1, step=1)

                line5, line6, line7, line8 = st.columns(4)
                with line5:
                    width_name1 = st.text_input('Width', value="Width", help=None)
                    if width_name1 in df.columns:
                        pass
                    else:
                        st.write('Width spelling is incorrect or different from the column name')
                with line6:
                    min_width2 = st.number_input("Width minimum value ", value=1, step=1)
                with line7:
                    max_width3 = st.number_input("Width maximum value", value=1, step=1)
                with line8:
                    wid_increment4 = st.number_input("Width increment value", value=1, step=1)

                line9, line10, line11, line12 = st.columns(4)
                with line9:
                    height_name1 = st.text_input("Height", value="Height", help=None)
                    if height_name1 in df.columns:
                        pass
                    else:
                        st.write("Height spelling is incorrect or different from the column name")

                with line10:
                    min_height2 = st.number_input("Height minimum value", value=1, step=1)
                with line11:
                    max_height3 = st.number_input("Height maximum value", value=1, step=1)
                with line12:
                    heit_increment4 = st.number_input("Height increment value", value=1, step=1)

                if st.form_submit_button(label='Click button'):

                    out1 = df.groupby(pd.cut(df[length_name1], np.arange(min_length2, max_length3 + 1, length_increment4)))[length_name1] \
                        .agg(**{'Min': 'min', 'Max': 'max', 'Length Count': 'count',
                                'Percentage': lambda x: 100 * x.size / len(df),
                                'Remaining': lambda x: len(df) - x.size})
                    out2 = df.groupby(pd.cut(df[width_name1], np.arange(min_width2, max_width3 + 1, wid_increment4)))[width_name1] \
                        .agg(**{'Min': 'min', 'Max': 'max', 'Width Count': 'count',
                                'Percentage': lambda y: 100 * y.size / len(df),
                                'Remaining': lambda y: len(df) - y.size})
                    out3 = df.groupby(pd.cut(df[height_name1], np.arange(min_height2, max_height3 + 1, heit_increment4)))[height_name1] \
                        .agg(**{'Min': 'min', 'Max': 'max', 'Height Count': 'count',
                                'Percentage': lambda z: 100 * z.size / len(df),
                                'Remaining': lambda z: len(df) - z.size})

                    st.dataframe("Length distribution:", out1)
                    st.write("Width distribution:", out2)
                    st.write("Height distribution:", out3)

with this code, I distributed the data in three different integer columns dynamically. But now i want to create histogram from the data.
How is this possible in streamlite?

Hi @hemanth_vema ,

Yes it is, I have created and plotted many Matplotlib charts in Streamlit and the key is to use ‘st.pyplot(fig)’ in the end, as the code below got from the Streamlit documentation (st.pyplot - Streamlit Docs).

import matplotlib.pyplot as plt
import numpy as np

arr = np.random.normal(1, 1, size=100)
fig, ax = plt.subplots()
ax.hist(arr, bins=20)

st.pyplot(fig)

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