mirror of
https://github.com/wassname/geopandas.git
synced 2026-09-19 12:43:17 +08:00
* Adding example for Plotting with Folium * Adding HeatMap in plotting with folium example * Adding HeatMap in plotting with folium example * Updating and tried to fix the issue. * Update examples/plotting_with_folium.ipynb Co-Authored-By: Martin Fleischmann <36797143+martinfleis@users.noreply.github.com> * Updated and made the suggested changes * Delete ne_110m_admin_0_countries.zip
280 KiB
280 KiB
In [1]:
# Importing Libraries
import pandas as pd
import geopandas
import folium
import matplotlib.pyplot as plt
from shapely.geometry import PointIn [2]:
df1 = pd.read_csv('volcano_data_2010.csv')
df = df1.loc[:, ("Year", "Name", "Country", "Latitude", "Longitude", "Type")]
df.info()<class 'pandas.core.frame.DataFrame'> RangeIndex: 63 entries, 0 to 62 Data columns (total 6 columns): Year 63 non-null int64 Name 63 non-null object Country 63 non-null object Latitude 63 non-null float64 Longitude 63 non-null float64 Type 63 non-null object dtypes: float64(2), int64(1), object(3) memory usage: 3.0+ KB
In [3]:
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()Out [3]:
| Year | Name | Country | Latitude | Longitude | Type | geometry | |
|---|---|---|---|---|---|---|---|
| 0 | 2010 | Tungurahua | Ecuador | -1.467 | -78.442 | Stratovolcano | POINT (-78.44199999999999 -1.467) |
| 1 | 2010 | Eyjafjallajokull | Iceland | 63.630 | -19.620 | Stratovolcano | POINT (-19.62 63.63) |
| 2 | 2010 | Pacaya | Guatemala | 14.381 | -90.601 | Complex volcano | POINT (-90.601 14.381) |
| 3 | 2010 | Sarigan | United States | 16.708 | 145.780 | Stratovolcano | POINT (145.78 16.708) |
| 4 | 2010 | Karangetang [Api Siau] | Indonesia | 2.780 | 125.480 | Stratovolcano | POINT (125.48 2.78) |
In [4]:
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
df.Type.unique()Out [4]:
array(['Stratovolcano', 'Complex volcano', 'Shield volcano',
'Subglacial volcano', 'Lava dome', 'Caldera'], dtype=object)In [5]:
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')Out [5]:
Text(0.5, 1.0, 'Volcanoes')
In [6]:
# Stamen Terrain
map = folium.Map(location = [13.406,80.110], tiles = "Stamen Terrain", zoom_start = 9)
mapOut [6]:
In [7]:
# OpenStreetMap
map = folium.Map(location = [13.406,80.110], tiles='OpenStreetMap' , zoom_start = 9)
mapOut [7]:
In [8]:
# Stamen Toner
map = folium.Map(location = [13.406,80.110], tiles='Stamen Toner', zoom_start = 9)
mapOut [8]:
In [9]:
#use terrain map layer to actually see volcano terrain
map = folium.Map(location = [4,10], tiles = "Stamen Terrain", zoom_start = 3)In [10]:
# insert multiple markers, iterate through list
# add a different color marker associated with type of volcano
geo_df_list = [[point.xy[1][0], point.xy[0][0]] for point in geo_df.geometry ]
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"
#now 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 [11]:
mapOut [11]:
In [12]:
# In this example, with the hep of heat maps, we are able to perceive the density of volcanoes
# which is more in some part 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)
mapOut [12]:
In [ ]: