mirror of
https://github.com/wassname/geopandas.git
synced 2026-09-21 13:00:14 +08:00
* DOC: revise plotting with folium example * DOC: edit example description * Revert "DOC: revise plotting with folium example" This reverts commit 58ad279dbc9d0030550566b27035b5e783a9291f. * DOC: revise plotting with folium example This commit also include feedback actions.
7.0 KiB
7.0 KiB
In [ ]:
# Import Libraries
import pandas as pd
import geopandas
import folium
import matplotlib.pyplot as pltIn [ ]:
df1 = pd.read_csv('volcano_data_2010.csv')
# Keep only relevant columns
df = df1.loc[:, ("Year", "Name", "Country", "Latitude", "Longitude", "Type")]
df.info()In [ ]:
# Create point geometries
geometry = geopandas.points_from_xy(df.Longitude, df.Latitude)
geo_df = geopandas.GeoDataFrame(df[['Year','Name','Country', 'Latitude', 'Longitude', 'Type']], geometry=geometry)
geo_df.head()In [ ]:
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
df.Type.unique()In [ ]:
fig, ax = plt.subplots(figsize=(24,18))
world.plot(ax=ax, alpha=0.4, color='grey')
geo_df.plot(column='Type', ax=ax, legend=True)
plt.title('Volcanoes')In [ ]:
# Stamen Terrain
map = folium.Map(location = [13.406,80.110], tiles = "Stamen Terrain", zoom_start = 9)
mapIn [ ]:
# OpenStreetMap
map = folium.Map(location = [13.406,80.110], tiles='OpenStreetMap' , zoom_start = 9)
mapIn [ ]:
# Stamen Toner
map = folium.Map(location = [13.406,80.110], tiles='Stamen Toner', zoom_start = 9)
mapIn [ ]:
# Use terrain map layer to see volcano terrain
map = folium.Map(location = [4,10], tiles = "Stamen Terrain", zoom_start = 3)In [ ]:
# Create a geometry list from the GeoDataFrame
geo_df_list = [[point.xy[1][0], point.xy[0][0]] for point in geo_df.geometry ]
# Iterate through list and add a marker for each volcano, color-coded by its type.
i = 0
for coordinates in geo_df_list:
#assign a color marker for the type of volcano, Strato being the most common
if geo_df.Type[i] == "Stratovolcano":
type_color = "green"
elif geo_df.Type[i] == "Complex volcano":
type_color = "blue"
elif geo_df.Type[i] == "Shield volcano":
type_color = "orange"
elif geo_df.Type[i] == "Lava dome":
type_color = "pink"
else:
type_color = "purple"
# Place the markers with the popup labels and data
map.add_child(folium.Marker(location = coordinates,
popup =
"Year: " + str(geo_df.Year[i]) + '<br>' +
"Name: " + str(geo_df.Name[i]) + '<br>' +
"Country: " + str(geo_df.Country[i]) + '<br>'
"Type: " + str(geo_df.Type[i]) + '<br>'
"Coordinates: " + str(geo_df_list[i]),
icon = folium.Icon(color = "%s" % type_color)))
i = i + 1In [ ]:
mapIn [ ]:
# This example uses heatmaps to visualize the density of volcanoes
# which is more in some parts of the world compared to others.
from folium import plugins
map = folium.Map(location = [15,30], tiles='Cartodb dark_matter', zoom_start = 2)
heat_data = [[point.xy[1][0], point.xy[0][0]] for point in geo_df.geometry ]
heat_data
plugins.HeatMap(heat_data).add_to(map)
map