(Package) folium

์ž„๊ฒฝ๋ฏผยท2023๋…„ 10์›” 12์ผ
1
post-thumbnail
post-custom-banner

๐Ÿ”‘Summarization


Python package - folium Basic


๐Ÿ“—Contents


  • ์„ค์น˜
pip install folium
  • ์‚ฌ์šฉ๋ฐฉ๋ฒ•
import folium

m = folium.Map(location = [45.5236, -122.6750])
m

  • Save Path : HTML ํŒŒ์ผ๋กœ ์ €์žฅ ๊ฐ€๋Šฅ
m = folium.Map(location = [45.5236, -122.6750])
m.save('index.html') # HTML ์ €์žฅ ๊ฐ€๋Šฅ

Tile option

  • tile : ์ง€๋„ ์Šคํƒ€์ผ ์ง€์ •
  • zoom_start : ์‹œ์ž‘๋ฐฐ์œจ ์„ค์ •
folium.Map(location=[45.5236, -122.6750], tiles='Stamen Toner', zoom_start=13)

folium.Marker()

  • ์ง€๋„์— ๋งˆ์ปค ์ƒ์„ฑ
my_map = folium.Map(location=[45.372, -121.6972], zoom_start=12, tiles='Stamen Terrain')

# ๋งˆ์ปค ์ถ”๊ฐ€ ๊ฐ€๋Šฅ
folium.Marker([45.3288, -121.6625], popup='<i>Mt. Hood Meadows</i>').add_to(my_map)
folium.Marker([45.3311, -121.7113], popup='<b>Timberline Lodge</b>').add_to(my_map) # popup : ๋งˆ์ปค์— ํ‘œ์‹œ๋˜๋Š” ๊ธ€๊ท€

my_map

folium.ClickForMarker()

  • ์ง€๋„ ์œ„์— ๋งˆ์šฐ์Šค๋กœ ํด๋ฆญํ–ˆ์„ ๋•Œ ๋งˆ์ปค๋ฅผ ์ƒ์„ฑ
m = folium.Map(
    location = [37.544564958079896, 127.05582307754338],
    zoom_start = 14,
    tiles = 'OpenStreetMap'
    )

m.add_child(folium.ClickForMarker(popup = 'ClickForMaker'))

folium.LatLngPopup()

  • ์ง€๋„๋ฅผ ๋งˆ์šฐ์Šค๋กœ ํด๋ฆญํ–ˆ์„ ๋•Œ ์œ„๋„/๊ฒฝ๋„ ์ •๋ณด๋ฅผ ๋ฐ˜ํ™˜
m = folium.Map(
    location = [37.544564958079896, 127.05582307754338],
    zoom_start = 14,
    tiles = 'OpenStreetMap'
    )

m.add_child(folium.LatLngPopup())

folium.Circle(), folium.CircleMarker()

  • folium.Circle() : ์ขŒํ‘œ์— ์›์„ ์ด์šฉํ•ด ํ‘œ์‹œ
  • folium.CircleMarker() : ์ขŒํ‘œ์— ์›์„ ์ด์šฉํ•ด ํ‘œ์‹œ

โ€ป ๋‘˜ ๊ฐ„์˜ ์ฐจ์ด์ 
1. folium.CircleMarker()๋Š” ๋ฐฐ์œจ์— ๋”ฐ๋ผ Circle์˜ radius๊ฐ€ ์ž๋™ ์กฐ์ • ๋จ
2. ๊ทธ ์™ธ ์˜ต์…˜์€ ๋ชจ๋‘ ๋™์ผ

# Circle Marker

m = folium.Map(location=[45.5236, -122.6750], zoom_start = 13, tiles = 'Stamen Terrain')

# ๋งˆ์ปค ์ถ”๊ฐ€ ๊ฐ€๋Šฅ
folium.Circle(
    radius = 100,
    location = [45.5244, -122.6699], 
    popup = 'The Waterfront',
    color = 'crimson',
    fill = False
).add_to(m)

folium.Circle(
    radius = 50,
    location = [45.5215, -122.6261],
    popup = 'Laurelhurst Park', 
    color = '#3186cc',
    fill = True,
    fill_color = '#3186cc'
).add_to(m)

m

๋‹ค์–‘ํ•œ ์˜ต์…˜๋“ค

folium.Circle() / folium.CircleMarker()

m = folium.Map(
    location = [37.544564958079896, 127.05582307754338],
    zoom_start = 14,
    tiles = 'OpenStreetMap'
)

# circle
folium.Circle(
    location = [37.555243442409406, 127.04370422643919],
    radius = 100,
    fill = True,
    color = '#eb9e34',
    fill_color = 'red',
    popup = 'circle popup',
    tooltip = 'circle tooltip'
).add_to(m)

# circle marker
folium.CircleMarker(
    location = [37.54347089498245, 127.04439204503],
    radius = 100,
    fill = True,
    color = '#34ebc6',
    fill_color = '#c634eb',
    popup = 'circleMarker popup',
    tooltip = 'circleMarker tooltip'
).add_to(m)

m

folium.Choropleth

  • ์ฃผ์–ด์ง„ ๋ฐ์ดํ„ฐ๋ฅผ polygon ํ˜•ํƒœ๋กœ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฒƒ
m = folium.Map(
    location = [43, -102],
    zoom_start = 3
)

m

  • fill_opacity : ์ฑ„์šฐ๊ธฐ ํˆฌ๋ช…๋„
  • line_opacity : ์„  ํˆฌ๋ช…๋„
  • legend_name : ๋ฒ”๋ก€ ์ด๋ฆ„
folium.Choropleth(
    geo_data = f_path + '02. us-states.json', # ๊ฒฝ๊ณ„์„  ์ขŒํ‘œ๊ฐ’์ด ๋‹ด๊ธด ๋ฐ์ดํ„ฐ
    data = state_data, # Series or DataFrame
    columns = ['State', 'Unemployment'], # DataFrame Columns
    key_on = 'feature.id',
    fill_color = 'BuPu',
    fill_opacity = 1, # 0-1
    line_opacity = 1, # 0-1
    legend_name = 'Unemployment rate(%)'
).add_to(m) # json file : ๊ฒฝ๊ณ„์„  ์ขŒํ‘œ๊ฐ’์ด ๋‹ด๊ธด ๋ฐ์ดํ„ฐ

m

post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€