센트로이드 좌표 그리기
전체 경계 상자(bounding box)를 그대로 그릴 수 없기 때문에, 경계 상자의 위치를 하나의 점(센트로이드)으로 요약해서 표시합니다. 이를 Basemap에 그리는 과정은 간단해요. 센트로이드를 계산한 뒤 경도와 위도를 분리하여 .scatter() 메서드에 전달하면 됩니다.
Basemap 객체 m은 미리 만들어 두었습니다. 데이터셋 tweets_sotu와 함수 calculateCentroid()도 로드되어 있어요.
이 연습은 강의의 일부입니다
Python으로 소셜 미디어 데이터 분석하기
연습 안내
- 센트로이드를 계산해
centroids에 저장하세요. - 대륙이 점 뒤에 보이도록
fillcontinents의zorder인수를 설정하세요. - 점을 그리세요.
latlon인수를 올바른 값으로 설정하는 것을 잊지 마세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Calculate the centroids for the dataset
# and isolate longitudue and latitudes
centroids = ____[____].apply(____)
lon = [x[0] for x in centroids]
lat = [x[1] for x in centroids]
# Draw continents, coastlines, countries, and states
m.fillcontinents(color='white', ____ = ____)
m.drawcoastlines(color='gray')
m.drawcountries(color='gray')
m.drawstates(color='gray')
# Draw the points and show the plot
____.____(____, ____, ____ = True, alpha = 0.7)
plt.show()