import streamlit as st
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.font_manager as fm
plt.rcParams['font.family'] = 'Malgun Gothic'
plt.rcParams['axes.unicode_minus'] = False # 음수 지정 x
sns.set(font='Malgun Gothic',
rc={'axes.unicode_minus' : False},
style='darkgrid'
)
st.set_page_config(page_title="Matplotlib & Seaborn 튜토리얼", layout="wide")
st.title("Matplotlib & Seaborn 튜토리얼") # 제목
tips = sns.load_dataset('tips')
st.subheader('데이터 미리보기')
# tip 데이터셋 출력
st.dataframe(tips.head())
st.subheader("1. 기본 막대 그래프")
fig, ax = plt.subplots(figsize=(10,6)) # 객체 지향 방식으로 차트 작성
## <https://seaborn.pydata.org/>
sns.barplot(data = tips, x = 'day', y = 'total_bill', ax = ax)
## <https://matplotlib.org/stable/api/index>
ax.set_title('요일별 평균 지불 금액') # matplotlib
ax.set_xlabel('요일') # matplotlib
ax.set_ylabel('평균 지불 금액($)') # matplotlib
# plt.show() # jupyter, colab에서 출력할 때 사용
## 웹상에 띄울 때 == streamlit
st.pyplot(fig)
그래프를 그리는 목적 == 예쁘게 (보기 좋게) 출력하기 위해
이를 위해
ax (객체지향)으로 접근할 경우 세부적으로 (더 세세하게) 접근할 수 있다.