folium 사이트 : https://python-visualization.github.io/folium/latest/
🍃 Leaflet.js
: javascript 기반의 반응형 map 라이브러리이다.
(https://leafletjs.com/)
pip install folium
import folium
m = folium.Map(location=(45.5236, -122.6750))
m
m.save("index.html")
folium.Map((45.5236, -122.6750), tiles="cartodb positron")
folium.Map(tiles='https://{s}.tiles.example.com/{z}/{x}/{y}.png', attr='My Data Attribution')
📌 툴팁(tooltip)
: 클릭 또는 마우스를 특정 요소에 놓았을 때 (hover) 정보 혹은 도움말 표시
(http://61.107.76.13/Li/04_40.html)
m = folium.Map([45.35, -121.6972], zoom_start=12)
folium.Marker(
location=[45.3288, -121.6625],
tooltip="Click me!",
popup="Mt. Hood Meadows",
icon=folium.Icon(icon="cloud"),
).add_to(m)
folium.Marker(
location=[45.3311, -121.7113],
tooltip="Click me!",
popup="Timberline Lodge",
icon=folium.Icon(color="green"),
).add_to(m)
m
m = folium.Map(location=[-71.38, -73.9], zoom_start=11)
trail_coordinates = [
(-71.351871840295871, -73.655963711222626),
(-71.374144382613707, -73.719861619751498),
(-71.391042575973145, -73.784922248007007),
(-71.400964450973134, -73.851042243124397),
(-71.402411391077322, -74.050048183880477),
]
folium.PolyLine(trail_coordinates, tooltip="Coast").add_to(m)
m
m = folium.Map((0, 0), zoom_start=7)
group_1 = folium.FeatureGroup("first group").add_to(m)
folium.Marker((0, 0), icon=folium.Icon("red")).add_to(group_1)
folium.Marker((1, 0), icon=folium.Icon("red")).add_to(group_1)
group_2 = folium.FeatureGroup("second group").add_to(m)
folium.Marker((0, 1), icon=folium.Icon("green")).add_to(group_2)
folium.LayerControl().add_to(m)
m
import requests
m = folium.Map(tiles="cartodbpositron")
geojson_data = requests.get(
"https://raw.githubusercontent.com/python-visualization/folium-example-data/main/world_countries.json"
).json()
folium.GeoJson(geojson_data, name="hello world").add_to(m)
folium.LayerControl().add_to(m)
m
import pandas
state_geo = requests.get(
"https://raw.githubusercontent.com/python-visualization/folium-example-data/main/us_states.json"
).json()
state_data = pandas.read_csv(
"https://raw.githubusercontent.com/python-visualization/folium-example-data/main/us_unemployment_oct_2012.csv"
)
m = folium.Map(location=[48, -102], zoom_start=3)
folium.Choropleth(
geo_data=state_geo,
name="choropleth",
data=state_data,
columns=["State", "Unemployment"],
key_on="feature.id",
fill_color="YlGn",
fill_opacity=0.7,
line_opacity=0.2,
legend_name="Unemployment Rate (%)",
).add_to(m)
folium.LayerControl().add_to(m)
m
folium
tooltip
leafletjs