DEV Community

Cover image for Top 4 python libraries to make beautiful Google maps🌐
Chinnureddy
Chinnureddy

Posted on

Top 4 python libraries to make beautiful Google maps🌐

1)Folium

Folium stands out as a top choice and probably the most popular in the industry for its interactivity and extensive customization options. With JavaScript at its core, it seamlessly integrates interactivity into map visualizations. To kickstart plotting post-installation, a simple call initiates the process, making it user-friendly and accessible to all levels of expertise.

import folium
map = folium.Map(location=(50, 0), zoom_start=8)#location - the center of the map, zoom_start - the resolution
map 
Enter fullscreen mode Exit fullscreen mode

Image description

We can use various default tiles or point to new ones:

map = folium.Map(location=(50, 0), zoom_start=8, tiles="Cartodb Positron")
map
Enter fullscreen mode Exit fullscreen mode

Image description

Let's now add all of the world's countries. To achieve this, I'll utilize the default geopandas dataframe:

import geopandas as gpd
df = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))

map = folium.Map(zoom_start=4, tiles="Cartodb Positron")
gdf_json = df.to_json()

folium.GeoJson(gdf_json).add_to(map)
map
Enter fullscreen mode Exit fullscreen mode

Image description

2)Plotly

Plotly is a versatile Python library for creating interactive and publication-quality visualizations.
It offers support for a wide range of chart types, including scatter plots, line charts, bar charts, and more.
With Plotly, users can easily customize their visualizations, add interactivity, and share their plots with others,You can find more details here

As a starting point, let's visualize the same geo pandas dataset but this time using the gdp_md_est variable. It is extremely easy to perform inside the following lines.


import plotly.express as px

fig = px.choropleth(df, locations='iso_a3', hover_name='name', 
                    color='gdp_md_est',
                    projection='natural earth')
fig.show()
Enter fullscreen mode Exit fullscreen mode

Image description

3) Geemap

geemap streamlines geospatial analysis in Python by seamlessly integrating with Google Earth Engine (GEE). With its interactive mapping capabilities, it offers users a convenient platform to visualize, analyze, and manipulate geospatial data efficiently. This package is particularly valuable for researchers, GIS professionals, and developers seeking to harness the power of GEE within the Python ecosystem.

As an illustration, let's gather land cover information from the Dynamic World product for an island situated in southern India.

import ee

radius = 1250 
point=ee.Geometry.Point([19.9, 60.2])
roi = point.buffer(radius) #setting a circle around the point of interest

DW = ee.ImageCollection("GOOGLE/DYNAMICWORLD/V1")\
                  .filterDate(start = '2023-07-08', end='2024-04-30')\
                  .filterBounds(roi) #getting the data
DW_list = DW.toList(DW.size()) #converting the data to GEE List
Enter fullscreen mode Exit fullscreen mode

Now we can do the plotting:

m = geemap.Map(center=[60.2, 19.9], zoom=14)

m.add_basemap('HYBRID') #adding a layer of Sentinel-2 imagery
viz_params = {'bands':'label', 'min':0, 'max':8,
'palette':['419bdf',
    '397d49',
    '88b053',
    '7a87c6',
    'e49635',
    'dfc35a',
    'c4281b',
    'a59b8f',
    'b39fe1']}
m.add_ee_layer(ee.Image(DW_list.get(9)), viz_params) #adding an image №9, as it has low cloud coverage for this area
m.add_legend(title="Dynamic World Land Cover", builtin_legend='Dynamic_World')
display(m)
Enter fullscreen mode Exit fullscreen mode

Image description

Geemap provides extensive functionality for Google Earth Engine tasks, but its usability may be challenging for those unfamiliar with ee library syntax and GEE concepts.

4)Ridgemap

This library is the last and truly my favorite one, since it allows to make truly unique plots, which are pieces of art.

Before plotting, let’s install two libs:

!pip install ridge_map mplcyberpunk
Enter fullscreen mode Exit fullscreen mode

Now let’s create a map:

import matplotlib.pyplot as plt
from  ridge_map import FontManager, RidgeMap
import ridge_map as rm
import mplcyberpunk
import matplotlib.font_manager as fm

plt.style.use("cyberpunk")
plt.rcParams["figure.figsize"] = (16,9)
# Define a font manager for the ridge map
fm = FontManager('https://google/fonts/blob/main/ofl/arbutusslab/ArbutusSlab-Regular.ttf?raw=true')

r = RidgeMap(bbox=(-15, 32, 45,90), font=fm.prop) #creating a map

values =r.get_elevation_data(num_lines=200) #getting elevation data
values = r.preprocess(values=values, #setting hypoparameters
   water_ntile=70,
   vertical_ratio=40,
   lake_flatness=3)

r.plot_map(values, label="Europe", label_x=0.4,label_y=-0.05, label_size=60, line_color=plt.get_cmap('inferno'), background_color="#212946")
mplcyberpunk.add_glow_effects() #adding glowing
Enter fullscreen mode Exit fullscreen mode

Image description

From my point of view, this is awesome! You can check out the library, find a plenty of other visualizations and post your own:)

Hopefully you’ll find these libraries helpful and worth including in your toolbox.

🛰️Follow for more🛰️

Top comments (1)

Collapse
 
chinnanj profile image
Chinnureddy

Share your favourite mapping library and why in one line!.