Python/Matplotlib 7

PIE, BAR, LINE, AREA ์ฐจํŠธ๋ฅผ ์ŠคํŠธ๋ฆผ๋ฆฟ(streamlit)์— ํ‘œํ˜„ํ•˜๊ธฐ

#์ŠคํŠธ๋ฆผ๋ฆฟ์˜ ๋‚ด์žฅ ์ฐจํŠธ ํ•จ์ˆ˜์™€ ์œ ๋ช…ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ธ plotly ์ฐจํŠธimport streamlit as stimport pandas as pdimport matplotlib.pyplot as pltimport plotly.express as pxdef main() : #์ŠคํŠธ๋ฆผ๋ฆฟ์—์„œ ์ œ๊ณตํ•ด์ฃผ๋Š” ์ฐจํŠธ #line_chart, area_chart df1 = pd.read_csv('./data/lang_data.csv') print(df1) print(df1.columns[ 1: ]) column_list = df1.columns[ 1: ] choice_list = st.multiselect('์–ธ์–ด๋ฅผ ์„ ํƒํ•˜์„ธ์š”', column_list) print(c..

Python/Matplotlib 2024.04.26

scatter, histogram ๋“ฑ์˜ ์ฐจํŠธ๋ฅผ ์ŠคํŠธ๋ฆผ๋ฆฟ(streamlit)์œผ๋กœ ํ‘œํ˜„ํ•˜๊ธฐ

# ์ฐจํŠธ ๊ทธ๋ฆฌ๊ธฐ ๋ฐฉ๋ฒ•import streamlit as stimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as sbdef main(): st.title('์ฐจํŠธ ๊ทธ๋ฆฌ๊ธฐ 1') df = pd.read_csv('./data/iris.csv') st.dataframe(df) # sepal_length ์™€ sepal_width์˜ ๊ด€๊ณ„๋ฅผ ์ฐจํŠธ๋กœ ๋‚˜ํƒ€๋‚ด์‹œ์˜ค fig1 = plt.figure() plt.scatter(data=df, x='sepal_length', y='sepal_width') plt.title('Sepal Length vs Width') st.pyplot(fig1..

Python/Matplotlib 2024.04.26

Matplotlib) Scatter(์Šค์บํ„ฐ) ์ฐจํŠธ์™€ HeatMap(ํžˆํŠธ๋งต) ๊ทธ๋ฆฌ๊ธฐ

Scatter(์Šค์บํ„ฐ) ์Šค์บํ„ฐ ํ”Œ๋กฏ์€ ๋ฐ์ดํ„ฐ์˜ ๋ถ„ํฌ๋ฅผ ์‹œ๊ฐ์ ์œผ๋กœ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋ฉฐ, ๋‘ ๋ณ€์ˆ˜ ๊ฐ„์˜ ๊ด€๊ณ„๋ฅผ ์ดํ•ดํ•˜๋Š” ๋ฐ ๋„์›€์ด ๋œ๋‹ค ์˜ˆ๋ฅผ ๋“ค์–ด, ๋‘ ๋ณ€์ˆ˜ ๊ฐ„์˜ ์–‘์˜ ์ƒ๊ด€ ๊ด€๊ณ„๊ฐ€ ์žˆ์„ ๋•Œ, ๋ฐ์ดํ„ฐ ํฌ์ธํŠธ๋“ค์€ ๋Œ€์ฒด๋กœ ์˜ค๋ฅธ์ชฝ ์œ„๋กœ ํ–ฅํ•˜๋Š” ๊ฒฝํ–ฅ์ด ์žˆ๋‹ค. ๋ฐ˜๋Œ€๋กœ ์Œ์˜ ์ƒ๊ด€ ๊ด€๊ณ„๊ฐ€ ์žˆ์„ ๋•Œ๋Š” ๋Œ€์ฒด๋กœ ์™ผ์ชฝ ์œ„๋กœ ํ–ฅํ•˜๋Š” ๊ฒฝํ–ฅ์ด ์žˆ๋‹ค.๋˜ํ•œ ์ƒ๊ด€๊ด€๊ณ„๊ฐ€ ๊ฐ•ํ• ๊ฒฝ์šฐ ๋ฐ์ดํ„ฐ๋“ค์ด ๋ชจ์—ฌ์žˆ๊ณ , ์ƒ๊ด€๊ด€๊ณ„๊ฐ€ ์•ฝํ•  ๊ฒฝ์šฐ ๋ฐ์ดํ„ฐ๋“ค์ด ํผ์ ธ์žˆ๋‹ค    import numpy as npimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as sb   # ๋ฐฐ๊ธฐ๋Ÿ‰(displ)๊ณผ ์—ฐ๋น„(comb)์˜ ๊ด€๊ณ„๋ฅผ ๋ˆˆ์œผ๋กœ ํ™•์ธํ•ด๋ณด๊ณ ์‹ถ๋‹ค df  displ pv2 pv4 city UCity ..

Python/Matplotlib 2024.04.16

Matplotlib) Histograms(ํžˆ์Šคํ† ๊ทธ๋žจ) ์ฐจํŠธ ๊ทธ๋ฆฌ๊ธฐ

- ์ฃผ์–ด์ง„ ๊ฐ ๊ตฌ๊ฐ„ ๋‚ด์— ์œ„์น˜ํ•˜๋Š” ๊ด€์ธก์น˜ ์ˆ˜๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ๊ทธ๋ž˜ํ”„์ด๋‹ค - ๋นˆ๋„ ๋ถ„ํฌ๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ๊ทธ๋ž˜ํ”„์ด๋‹ค- ์ผ์ •ํ•œ ํ•ด๋‹น ๊ตฌ๊ฐ„์— ํฌํ•จ๋˜๋Š” ๋ฐ์ดํ„ฐ์˜ ๋ถ„ํฌ๋ฅผ ์•Œ ์ˆ˜ ์žˆ๋‹ค- ์ผ์ • ๊ตฌ๊ฐ„์„ bin์ด๋ผ๊ณ  ํ•˜๋ฉฐ ๊ตฌ๊ฐ„์ด ์—ฌ๋Ÿฌ๊ฐœ๋ฉด ๋ณต์ˆ˜ํ˜•์œผ๋กœ bins๋ผ๊ณ  ํ•œ๋‹ค- ํžˆ์Šคํ† ๊ทธ๋žจ์€ ๋˜‘๊ฐ™์€ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ง€๊ณ  bin์„ ์–ด๋–ป๊ฒŒ ์„ค์ •ํ•˜๋Š๋ƒ์— ๋”ฐ๋ผ์„œ ์ฐจํŠธ๋ชจ์–‘์ด ๋‹ฌ๋ผ์ง€๋ฉฐ ํ•ด์„์ด ๋‹ฌ๋ผ์ง„๋‹ค   df  id species hp attack defense speed01bulbasaur4549494512ivysaur6062636023venusaur8082838034charmander3952436545charmeleon58645880.....................802803poipole67736773803804naganadel737373121..

Python/Matplotlib 2024.04.15

Matplotlib) Pie (ํŒŒ์ด) ์ฐจํŠธ ๊ทธ๋ฆฌ๊ธฐ

๋ฐ์ดํ„ฐ๋ฅผ ํผ์„ผํ…Œ์ด์ง€๋กœ ๋น„๊ตํ•ด์„œ ๋ณด๊ณ ์‹ถ์„๋•Œ Pie chart(ํŒŒ์ด ์ฐจํŠธ)๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค  ํฌ์ผ“๋ชฌ ๋ฐ์ดํ„ฐ๋ฅผ ์ด์šฉํ•˜์—ฌ Pie chart๋ฅผ ๊ทธ๋ ค๋ณด์ž  df idspeciesgeneration_idheightweightbase_experiencetype_1type_201bulbasaur10.76.964grasspoison12ivysaur11.013.0142grasspoison23venusaur12.0100.0236grasspoison34charmander10.68.562fireNaN45charmeleon11.119.0142fireNaN...........................802803poipole70.61.8189poisonNaN803804naganadel73.6150.0243poisondragon80480..

Python/Matplotlib 2024.04.15

Matplotlib) Bar chart : countplot ์ฐจํŠธ ๊ทธ๋ฆฌ๊ธฐ

import numpy as npimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as sb  ํฌ์ผ“๋ชฌ๋ฐ์ดํ„ฐ๊ฐ€ ์žˆ๋‹ค. idspeciesgeneration_idheightweightbase_experiencetype_1type_201bulbasaur10.76.964grasspoison12ivysaur11.013.0142grasspoison23venusaur12.0100.0236grasspoison34charmander10.68.562fireNaN45charmeleon11.119.0142fireNaN...........................802803poipole70.61.8189poisonNaN803804naganadel73.6150...

Python/Matplotlib 2024.04.15

Matplotlib) ๊ทธ๋ž˜ํ”„ ๋””์ž์ธ ๋ณ€๊ฒฝ ์‹œ ์‚ฌ์šฉํ•˜๋Š” ํ•จ์ˆ˜ ์•Œ์•„๋ณด๊ธฐ

import pandas as pdimport numpy as npimport matplotlib.pyplot as plt   #๋ณ„์นญ์ง€์ •import seaborn as sb MatplotlibํŒŒ์ด์ฌ ์‹œ๊ฐํ™” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ plot() : ๋‹ค์ด์–ด๊ทธ๋žจ์— ์ (๋งˆ์ปค)์„ ๊ทธ๋ฆฌ๋Š”๋ฐ ์‚ฌ์šฉํ•œ๋‹คmarker : ์ง€์ •๋œ ๋งˆ์ปค๋กœ ๊ฐ ์ง€์ ์„ ๊ฐ•์กฐํ•  ์ˆ˜ ์žˆ๋‹ค linestyle : ํ”Œ๋กฏ๋œ ์„ ์˜ ์Šคํƒ€์ผ์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค xlable(), ylable() : x์ถ•๊ณผ y์ถ•์— ๋Œ€ํ•œ ๋ ˆ์ด๋ธ”์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค grid() : ํ”Œ๋กฏ์— ๊ทธ๋ฆฌ๋“œ ์„ ์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค     subplot() : ์—ฌ๋Ÿฌ ๊ทธ๋ž˜ํ”„๋ฅผ ๊ทธ๋ฆด ์ˆ˜ ์žˆ๋‹ค ex)plt.subplot(1,2,2) #1์ค„์— ๋‘์นธ์— ๋‘๋ฒˆ์งธ์— ๊ทธ๋ž˜ํ”„๋ฅผ ํ‘œ์‹œํ•œ๋‹คex) grid( axis = 'y' )    #๊ทธ..

Python/Matplotlib 2024.04.09