본문 바로가기

프로그래머스 데브 코스/TIL

[6기] 프로그래머스 인공지능 데브코스 21일차 TIL

0921

5주차-Day4) 먼슬리 프로젝트

EDA와 웹 연동

이어서 최종 코드까지 전시
ax1 = plt.subplot(1, 2, 1)
plt.plot(gu_df['Country'], gu_df['Birth Rate'], '.-')
plt.title('Birth Rate: Highest GDP')
plt.xlabel('Top 20 Countries')
plt.ylabel('Birth Rate')
plt.xticks(rotation=90)

ax2 = plt.subplot(1, 2, 2, sharey=ax1)
plt.plot(gd_df['Country'], gd_df['Birth Rate'], '.-')
plt.title('Birth Rate: Lowest GDP')
plt.xlabel('Top 20 Countries')
plt.xticks(rotation=90)

plt.tight_layout()
plt.show()
plt.figure(figsize=(10, 6))
plt.scatter(re_df['GDP'], re_df['Birth Rate'], color='green', alpha=0.5, label='Birth Rate')
plt.scatter(re_df['GDP'], re_df['Fertility Rate'], color='red', alpha=0.5, label='Fertility Rate')
plt.title('Birth Rate/Fertility Rate vs GDP, Top 20 Countries (without US&China)')
plt.xlabel('GDP')
plt.ylabel('Fertility Rate / Birth Rate')
plt.legend()
plt.show()
import geopandas as gpd
from shapely.geometry import Point

geometry = [Point(xy) for xy in zip(df['Longitude'], df['Latitude'])]   # 데이터셋에 있는 위도/경도 열을 불러와 지도 그래프 위에 point(점) 찍기
gdf = gpd.GeoDataFrame(df, geometry=geometry, crs='EPSG:4326')          # 제공해주는 지도 데이터프레임 이용하기

world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
fig, ax = plt.subplots(figsize=(10, 6))

world.plot(ax=ax, color='lightgrey', edgecolor='black')

scatter = plt.scatter(x = df['Longitude'], y = df['Latitude'], s = df["Birth Rate"]**2, c='#fd1132',  alpha=0.2)    # 출산율 산점도로 표시하기(s(size) 값 제곱으로 해 크기에 확실한 차이 두기)

for x, y, label in zip(gdf.geometry.x, gdf.geometry.y, gdf['Country']):
    if label in ['United States of America', 'Canada', 'Russia',
                 'China', 'Australia','Pakistan','India','Brazil', 'Kazakhstan','Algeria', 'Saudi Arabia']:         # 지도 그래프 위에 주요 국가 이름 표시하기
        ax.text(x, y, label.split(' ')[0], fontsize=8, ha='right', color='black', weight='bold', alpha=0.9)
    else:
        ax.text(x, y, '', fontsize=8, ha='right', color='darkslategrey', weight='bold', alpha=0.7)

plt.title('Birth Rate of Countries', fontsize=16, fontweight='bold')

plt.show()