1. What is Folium?
Folium makes it easy to visualize data that's been manipulated in Python on an interactive leaflet map. It enables both the binding of data to a map for choropleth visualizations as well as passing rich vector/raster/HTML visualizations as markers on the map.
2. How to use Folium
Step 1 : Import library folium
import folium
Step 2 : Set the center of map's frame
To start map with sight we want, we need to set center latitude and longitude of map's frame. We usually calculate latitude and longitude as mean of our dataset. Our workflow for setting the center is same as below :
- Calculate latitude of the center of the map.
- Calculate longitude of the center of the map.
- Store latitude and longitude in list object.
- Create frame object m using folium.Map() method.
- Parameter location got list of latitude and longitude.
- Parameter zoom_start got integer.
import folium
latitude_center = df.latitude.mean()
longitude_center = df.longitude.mean()
location = [latitude_center, longitude_center]
map = folium.Map(location = location, zoom_start = 13)
Step 3 : Add markes to map
After making frame of map, now we can add marker from our dataset. folium.CircleMarker() method helps us to add data point with unique latitude and longitude to our created map. Using varius parameters, we can make various style of markers.
After create marker using folium.CircleMap(), we must add Markers.add_to() method to add markers to our map.
map = folium.Map(location = location, zoom_start = 13)
# Add each data point to map
for i in df.shape[0] :
tooltip = df.loc[i, 'name']
latitude = df.latitude.iloc[i]
longitude = df.longitude.iloc[i]
folium.CircleMap([latitude, longitude],
tooltip = tooltip,
radius = 10,
color = 'crimson').add_to(map)
Step 4 : View created map
'Language > Python' 카테고리의 다른 글
[chardet] Encoding and Representing Text (0) | 2022.09.22 |
---|---|
[csv] Read files (0) | 2022.09.22 |
[heapq] Implementing Binary Heap in Python (0) | 2022.09.14 |
[queue] Implementing Priority Queue in Python (0) | 2022.09.14 |
[Syntax] Exception (0) | 2022.09.14 |