๊ณต๊ณต๋ฐ์ดํฐ ์๊ฐํ ์ฐ์ต์ฉ
๐ ๋ฐ์ดํฐ ์ ์ฒ๋ฆฌ
๋ผ์ด๋ธ๋ฌ๋ฆฌ import
import requests
import pandas as pd
import warnings
warnings.filterwarnings('ignore')
๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
df = pd.read_csv("./accessibility_data/seoul_parkinglot.csv")
df.head()
์ฃผ์ ์ปฌ๋ผ ๋ฐ์ดํฐ ํ์ ๋ณ๊ฒฝ & ์ฃผ์ฐจ์ฅ ํ๋ณด์จ์ ์์์ ์๋ 2๋ฒ์งธ ์๋ฆฌ๊น์ง
df2 = df2.astype({'์๋์ฐจ๋ฑ๋ก๋์ (๋)':'int', '์ฃผ์ฐจ๋ฉด์ (๋ฉด์)':'int', '์ฃผ์ฐจ์ฅํ๋ณด์จ (%)':'float'})
df2['์ฃผ์ฐจ์ฅํ๋ณด์จ (%)'] = round(df2['์ฃผ์ฐจ์ฅํ๋ณด์จ (%)'], 2)
df2.head()
๐ ๋ฐ์ดํฐ ์๊ฐํ
์์น๊ตฌ๋ณ ์ฃผ์ฐจ ๋ฉด์ ์๊ฐํ : Plotly.graph_objects ์ด์ฉ
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Bar(x = df2['์์น๊ตฌ'], y = df2['์ฃผ์ฐจ๋ฉด์ (๋ฉด์)']))
fig.update_layout(title = '์์น๊ตฌ๋ณ ์ฃผ์ฐจ๋ฉด์')
fig.show()
์์น๊ตฌ๋ณ ์ฃผ์ฐจ ๋ฉด์ ์๊ฐํ : plotly.express ์ด์ฉ
import plotly.express as px
fig = px.bar(df2, x='์์น๊ตฌ', y=['์๋์ฐจ๋ฑ๋ก๋์ (๋)', '์ฃผ์ฐจ๋ฉด์ (๋ฉด์)'],
title='์์น๊ตฌ๋ณ ์๋์ฐจ ๋ฑ๋ก ๋์, ์ฃผ์ฐจ ๋ฉด์ ๋ฐ ์ฃผ์ฐจ์ฅ ํ๋ณด์จ')
fig.show()
์์น๊ตฌ๋ณ ์ฃผ์ฐจ์ฅ ํ๋ณด์จ ์๊ฐํ : Plotly.graph_objects ์ด์ฉ
- Scatter plot์ผ๋ก ์ ์ด ์๋ ์ ๊ทธ๋ํ ๊ทธ๋ฆฌ๊ธฐ
- mode = 'lines+markers'
- ๊ฐ์กฐํ๊ณ ์ถ์ ๋ถ๋ถ ์ฌ๊ฐํ์ผ๋ก ํ์ํ๊ธฐ
- highlight_start ์, highlight_end (์์์ ๊ณผ ๋์ ์์น ์ง์ )
- fig.add_shape( ) ๋ก ์ฌ๊ฐํ ํ์
fig = go.Figure()
fig.add_trace(go.Scatter(x = df2['์์น๊ตฌ'], y=df2['์ฃผ์ฐจ์ฅํ๋ณด์จ (%)'], mode = 'lines+markers', name ='์ฃผ์ฐจ์ฅํ๋ณด์จ (%)'))
fig.update_xaxes(tickangle = 45)
highlight_start = 21.5
highlight_end = 22.5
fig.add_shape(type='rect',
x0 = highlight_start, y0 = 0,
x1 = highlight_end, y1 = 200,
fillcolor = 'rgba(255, 0, 0, 0.2)',
line=dict(color='pink', width=2))
fig.show()
728x90