스트림릿에서 차트를 그릴수있다.
sepal_length와 sepal_width의 관계를 scatter 차트로 나타내보자
in:
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)
out:

# 스트림릿에서 pyplot이나 seaborn 차트를 나타낼때 plt.show 함수대신 st.pyplot 함수를 사용한다.
regplot을 사용해보자
in:
fig3 = plt.figure()
sns.regplot(data= df, x='sepal_length', y= 'sepal_width')
st.pyplot(fig3)
out:

# 꽃받침의 너비와 길이는 별 관계 없어 보인다.
히스토그램을 만들고 bin의 개수는 20개로 설정한다.
in:
fig4 = plt.figure()
plt.hist(data= df, x='sepal_length',bins=20, rwidth=0.8)
st.pyplot(fig4)
out:

sepal_length의 히스토그램을 그리되 bin의 개수를 10개와 20개로 두개의 차트를 수평으로 보여주자
in:
fig5 = plt.figure(figsize=(12,5))
plt.subplot(1,2,1)
plt.hist(data=df,x='sepal_length',rwidth=0.8, bins = 10)
plt.subplot(1,2,2)
plt.hist(data=df,x='sepal_length',rwidth=0.8, bins = 20)
st.pyplot(fig5)
out:

# subplot을 활용하여 두개의 차트를 하나의 영역에서 보여줬다.
species는 각각 몇개인지 데이터 프레임의 차트로 그린다.
in:
fig7 = plt.figure()
df['species'].value_counts().plot(kind='bar')
st.pyplot(fig7)
out:
# 균등하게 분포되었다.
sepal_length 컬럼을 히스토그램으로 나타내자.
in:
fig8 = plt.figure()
df['sepal_length'].hist(bins=40)
st.pyplot(fig8)
out:

'Streamlit' 카테고리의 다른 글
[Streamlit] 로컬에서 만든 앱을 AWS로 배포, 가상환경 구성: joblib (0) | 2022.05.20 |
---|---|
[Streamlit] 반응형 차트 만들기 (0) | 2022.05.20 |
[Streanlit] 파일 분리 작업 (0) | 2022.05.20 |
[Streamlit] sidebar 메뉴, 파일 업로드 기능 (0) | 2022.05.19 |
[Streamlit] 반응형 입력도구, 멀티미디어 삽입, 입력 받기: button, radio, checkbox, selectbox, multiselect, slider, expander, image, video, audio, text_input, number_input, date_input, time_input, color_picker (0) | 2022.05.19 |
댓글