# -*- coding: utf-8 -*-
import pandas as pd
import folium
import webbrowser
import json
gasan_map =folium.Map(location =[37.468,126.886],zoom_start=30)
gasan_map.save('folium_kr.html')
#webbrowser.open_new("folium_kr.html")
'''
Map함수에 tiles 옵션을 적용하면 지도에 적용하는 스타일을 변경하여 지정가능
Stamen Terrain 맵과 Stamen Toner 맵 스타일 비교
-서울 지도 만들기
'''
seoul_map2= folium.Map(location=[37.55,126.98],tiles='Stamen Terrain',zoom_start=12)
seoul_map3= folium.Map(location=[37.55,126.98],tiles='Stamen Toner',zoom_start=15)
seoul_map2.save('seoul_map2.html')
seoul_map3.save('seoul_map3.html')
# webbrowser.open_new("seoul_map2.html")
# webbrowser.open_new("seoul_map3.html")
''''''
#대학교 리스트를 데이터 프레임 변환
# df = pd.read_excel("./서울지역 대학교 위치.xlsx")
# #서울 지도 만들기
# seoul_map = folium.Map(location=[37.55,126.98],tiles='Stamen Terrain',zoom_start=12)
# #컬럼이 없으니까 열 추가
# df.columns = ['index', '위도', '경도']
# #대학교 위치정보를 Marker로 표시
# #인덱스열로 지정 하기
# df.set_index('index',inplace=True)
# for name, lat, lng in zip(df.index, df.위도, df.경도):
# folium.CircleMarker([lat, lng],
# radius =10, #원의 반지름
# color='brown',#원의 둘레 색상
# fill=True,
# fill_color='coral',
# fill_opacity=0.7, #투명도
# popup=name).add_to(seoul_map)
'''지도 영역에 단계 구분도
-행정구역과 같이 지도 상의 어떤 경계에 둘러싸인 영역에 색을 칠하거나 음영등으로 정보를 나타내는 시각화 방법
-전달하려는 정보의 값이 커지면 영역에 칠해진 색이나 음영이 진해진다
'''
#경기도 인구변화 데이터를 불러와서 데이터프레임 df로 변환, 경기도인구데이터.xlsx
df = pd.read_excel("C:/Users/Hoon/Desktop/엔코아 파이썬/데이터 시각화/경기도인구데이터.xlsx")
df.set_index('구분',inplace=True)
df.columns=df.columns.map(str)
#경기도 지도 만들기
g_map = folium.Map(location=[37.5502,126.982],tiles='Stamen Terrain', zoom_start=8)
#지도 경계 딕셔너리 데이터
json_path = './경기도행정구역경계.json'
gy_data = json.load(open(json_path, encoding='utf-8'))
folium.Choropleth(geo_data=gy_data).add_to(g_map)
df_json = pd.read_json(json_path)
dt1 = df_json.iloc[0,1]
print(len(df_json['features'][0]['geometry']['coordinates'][0]))
#feature > properties > 'name' : 양평군
#feature > geometry > coordinates : 좌표값들
#자동으로 folium.Choropleth(geo_data=gy_data).add_to(g_map) 에서 작업
#2017년의 인구 분포 저장
year = '2017'
# Choropleth 클래스로 단계구분도 표시하기
folium.Choropleth(geo_data=gy_data,
data = df[year], #표시하려는 데이터
columns=[df.index,df[year]], #열 지정
fill_color='PuRd',
bins=[10000,100000,300000,500000,700000], #오른쪽 상단 바 지정
key_on='feature.properties.name').add_to(g_map)
#지도를 HTML로 저장하기
g_map.save('./g_map'+year+'.html')
webbrowser.open_new('g_map2017.html')
# seoul_map.save('./seoul_colleges.html')
# webbrowser.open_new("seoul_colleges.html")
'Python' 카테고리의 다른 글
Python - Pandas 데이터 전처리 (0) | 2022.10.04 |
---|---|
Python - Seaborn 3 (0) | 2022.10.01 |
Python -seaborn 그래프 -2 (0) | 2022.10.01 |
Python - Seaborn 데이터셋, 그래프 그리기 (1) | 2022.09.30 |
Python - Pandas 여러 그래프 시각화 (0) | 2022.09.30 |