Làm việc với Folium

Trực quan hóa dữ liệu không gian địa lý bằng Python

Mary van Valkenburg

Data Science Program Manager, Nashville Software School

biểu đồ đa giác xanh nhạt với các điểm vị trí tác phẩm nghệ thuật

Trực quan hóa dữ liệu không gian địa lý bằng Python

Folium

  • gói Python
  • bản đồ tương tác
  • xây dựng trên Leaflet.js

logo lá của folium

Trực quan hóa dữ liệu không gian địa lý bằng Python

folium.Map()

import folium
# construct a map centered at the Eiffel Tower
eiffel_tower = folium.Map(location = [48.8583736,2.2922926])

# display the map
display(eiffel_tower)
Trực quan hóa dữ liệu không gian địa lý bằng Python

bản đồ đường phố Paris

Trực quan hóa dữ liệu không gian địa lý bằng Python

Thiết lập mức thu phóng

import folium
# construct a map centered at the Eiffel Tower
eiffel_tower = folium.Map([location = 48.8583736,2.2922926], zoom_start = 12)

# display the map
display(eiffel_tower)
Trực quan hóa dữ liệu không gian địa lý bằng Python

bản đồ đường phố Paris phóng to với tháp Eiffel nhỏ

Trực quan hóa dữ liệu không gian địa lý bằng Python

Tọa độ Folium từ trọng tâm

district_one.head()
district  center                   geometry
1         POINT (-86.860 36.262)   (POLYGON ((-86.771 36.383...    
center_point = district_one.center[0]
type(center_point)
<class 'shapely.geometry.point.Point'>
Trực quan hóa dữ liệu không gian địa lý bằng Python

Tọa độ Folium từ trọng tâm

# reverse the order for folium location array
district_center = [center_point.y, center_point.x]

# print center point and district_center
print(center_point)
print(district_center)
POINT (-86.86086595994405 36.2628221811899)
[36.262822181189904, -86.86086595994405]
Trực quan hóa dữ liệu không gian địa lý bằng Python

Thêm đa giác vào bản đồ folium

# create a folium map centered on district 1
district1_map = folium.Map(location = district_center)
# add the outline of district one
folium.GeoJson(district_one.geometry).add_to(district1_map)
# display the resulting map
display(district1_map)
Trực quan hóa dữ liệu không gian địa lý bằng Python

bản đồ với đa giác màu xanh lam

Trực quan hóa dữ liệu không gian địa lý bằng Python

Cùng luyện tập nào!

Trực quan hóa dữ liệu không gian địa lý bằng Python

Preparing Video For Download...