开始使用免费开始使用

绘制质心坐标

由于无法直接绘制整个边界框,我们用一个称为质心的单个点来概括其位置。在 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()
编辑并运行代码