본문 바로가기

Library/Streamlit

Streamlit - Chart

반응형
Chart

 

 

 

import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

def main() :
    st.title('차트 그리기 1')

    df = pd.read_csv('data2/iris.csv')
    st.dataframe(df)

 

 

 

scatter

 

 

 fig = plt.figure()
    plt.scatter(data=df, x='sepal_length', y='sepal_width')

    plt.title('sepal length vs width')
    plt.xlabel('Sepal Length')
    plt.ylabel('Sepal Width')
    st.pyplot(fig)

 

 

 

 

scatterplot

 

fig2 = plt.figure()
    sns.scatterplot(data=df, x='sepal_length', y='sepal_width')

    st.pyplot(fig2)

 

 

 

 

regplot

 

 

fig3 = plt.figure()
    sns.regplot(data=df, x='sepal_length', y='sepal_width')
    st.pyplot(fig3)

 

 

 

 

histogram

 

 

 fig4 = plt.figure(figsize= (10,4))
    plt.hist(data=df, x='sepal_length', bins=20, rwidth=0.8)
    st.pyplot(fig4)

 

 

 

 

 

subplot

 

 

fig5 = plt.figure()
    plt.subplot(1, 2, 1)
    plt.hist(data=df, x='sepal_length', bins=10, rwidth=0.8)
    plt.subplot(1, 2, 2)
    plt.hist(data=df, x='sepal_length', bins=20, rwidth=0.8)
    st.pyplot(fig5)

 

 

 

 

 

countplot

 

 

 fig6 = plt.figure()
    sns.countplot(data=df, x='species')
    st.pyplot(fig6)

 

반응형