始める無料で始める

重心座標のプロット

バウンディングボックス全体をプロットすることはできないため、バウンディングボックスの位置を「重心」と呼ばれる1つの点に要約します。この重心を 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()
コードを編集して実行