개발공부

[Streamlit] plotly를 이용한 차트그리기 본문

Python/Streamlit

[Streamlit] plotly를 이용한 차트그리기

mscha 2022. 5. 23. 12:31

Streamlit 라이브러리의 plotly_chart() 를 사용하면 된다.

prog_languages_data.csv
0.00MB

import streamlit as st
import pandas as pd
import plotly.express as px

def main():
    # plotly 라이브러리를 이용한 차트 그리기.

    df4 = pd.read_csv('data2/prog_languages_data.csv', index_col=0)
    st.dataframe(df4)

    # plotly 의 pie 차트
    fig1= px.pie(df4, names='lang', values='Sum',
            title= '각 언어별 파이차트')
    st.plotly_chart(fig1)

    # plotly 의 bar 차트
    df4_sorted = df4.sort_values('Sum', ascending = False)

    fig2 = px.bar(df4_sorted, x='lang', y='Sum')
    st.plotly_chart(fig2)
    

if __name__=='__main__':
    main()