ComenzarEmpieza gratis

Plotting centroid coordinates

Because we can't plot whole bounding boxes, we summarize the bounding box location into a single point called a centroid. Plotting these on a Basemap map is straightforward. Once we calculate the centroids, we separate the longitudes and latitudes, then pass to the .scatter() method.

The Basemap object m has been created for you. The dataset tweets_sotu and function calculateCentroid() have also been loaded.

Este ejercicio forma parte del curso

Analyzing Social Media Data in Python

Ver curso

Instrucciones del ejercicio

  • Calculate the centroids and store in centroids.
  • Set the argument zorder in fillcontinents such that the continents appear behind the points.
  • Plot the points. Remember to set the latlon argument to the correct value.

Ejercicio interactivo práctico

Prueba este ejercicio completando el código de muestra.

# 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()
Editar y ejecutar código