Pandas
Interactive Map in Python

Interactive Map in Python

Task: To plot all hydros of district with max hydro in province 6, Nepal

Installing library

!pip install geopandas
!pip install geoplot

Importing library

import geoplot as gplt
import geopandas as gpd
import geoplot.crs as gcrs
import imageio
import pandas as pd
import pathlib
import matplotlib.pyplot as plt
import mapclassify as mc
import numpy as np
from shapely.geometry import Point
import pandas as pd

Reading data of hydro powers

path = '.../Data/hydropower-projects.csv'
df = pd.read_csv(path)
df.head(2)
df_6 = df[df['Province']=='Province 6']
df_6["District"].value_counts().nlargest(n=1)
df_dis = df_6[df_6['District']== 'JAJARKOT']
df_dis.head(1)
#Converting lat and long values to form suitable for plotting
long = df_dis['Longitude'].values
lat = df_dis['Latitude'].values
projects = df_dis['Project'].values
capacity = df_dis['Capacity (MW)'].values
gdf_dis = gpd.GeoDataFrame(df_dis, geometry=gpd.points_from_xy(df_dis.Longitude,df_dis.Latitude))
gdf_dis.head(2)

Libraries for visualization

# visualization
import matplotlib.pyplot as plt
import folium
import plotly.express as px

Basic map

# plot base map
m = folium.Map(location=[29, 85], # center of the folium map
               tiles='cartodbpositron', # type of map
               min_zoom=4, max_zoom=30, # zoom range
               zoom_start=7,width="%100",height="%50")
m

Map with layers

#fig2=figure(width=550,height=350)
m2=folium.Map(location=[29, 82],width="%100",height="%50")
#fig2.add_child(m2)
folium.TileLayer('Stamen Terrain').add_to(m2)
folium.TileLayer('Stamen Toner').add_to(m2)
folium.TileLayer('Stamen Water Color').add_to(m2)
folium.TileLayer('cartodbpositron').add_to(m2)
folium.TileLayer('cartodbdark_matter').add_to(m2)
folium.LayerControl().add_to(m2)
m2

Map with hydros in Jajarkot with markers

#CRS conversion
gdf_dis_crs = gdf_dis.set_crs(epsg = "4326", inplace = True)
m3=folium.Map(location=[29, 82],tiles='cartodbpositron',zoom_start=9,width="%80",height="%50")

#Adding markers to the map
for i in range(len(projects)):
  folium.Marker(location=[lat[i],long[i]],popup=projects[i],tooltip=capacity[i]).add_to(m3)

m3