Plotting Google Map using folium package?

PythonServer Side ProgrammingProgramming

Folium is a very powerful python library which let you create seveal kind of Leaflet maps. As Leaflet/folium maps are interactive, so they are ideal for making dashborad building.


Installing folium is very easy using pip −

$pip install folium

Like you can see from the below screenshot, you just need to type above command in your console/cmd and pip will install the folium as well as dependencies for your python installation.

Basic Map

#Import library
import folium

#Uses lat then lon. & zoomlevel 4.The bigger the zoom number, the closer in you get.
mapOBJ = folium.Map(location=[17.3616, 78.4747], zoom_start = 4, tiles = 'Stamen Terrain')

# save method of Map object, will create a map'map2.html')


Case#2: GeoJson

import folium
import os
from folium import features
import numpy as np
import pandas as pd

N = 1000

lons = +5 - np.random.normal(size=N)
lats = 48 - np.random.normal(size=N)

data = {
   'type': 'FeatureCollection',
   'features': [
         'type': 'Feature',
         'geometry': {
            'type': 'MultiPoint',
            'coordinates': [[lon, lat] for (lat, lon) in zip(lats, lons)],
         'properties': {'prop0': 'value0'}
m = folium.Map([17.3616, 78.4747], zoom_start = 10)


Case#3: Marker, Icon, Popup

import folium
from folium import features

m = folium.Map([17.3616, 78.4747], zoom_start = 15)
mk = features.Marker([17.3616, 78.4747])
pp = folium.Popup('Charminar')
ic = features.Icon(color='red')




I have used one new library- vincent, Vincent takes Python data structures (tuples, lists, dicts, and Pandas DataFrames) and translates them into Vega visualization grammar.

Using pip, its very easy to install vincent.

$pip install vincent
C:\WINDOWS\system32>pip install vincent
Collecting vincent
Requirement already satisfied: pandas in c:\python\python361\lib\site-packages (from vincent) (0.20.2)
Requirement already satisfied: pytz >= 2011k in c:\python\python361\lib\site-packages (from pandas -> vincent) (2017.2)
Requirement already satisfied: python-dateutil >= 2 in c:\python\python361\lib\site-packages (from pandas -> vincent) (2.6.0)
Requirement already satisfied: numpy >= 1.7.0 in c:\python\python361\lib\site-packages (from pandas -> vincent) (1.16.0)
Requirement already satisfied: six >= 1.5 in c:\python\python361\lib\site-packages (from python-dateutil >= 2 -> pandas -> vincent) (1.10.0)
Building wheels for collected packages: vincent
Running bdist_wheel for vincent ... done
Stored in directory: C:\Users\rajesh\AppData\Local\pip\Cache\wheels\4c\0d\8a\65f34c765c6094a71cce3e42a49a26533eef61695e9b505f03
Successfully built vincent
Installing collected packages: vincent
Successfully installed vincent-0.4.4

import folium
from folium import features
import numpy as np
import json
import vincent

N = 100

multi_iter2 = {
   'x': np.random.uniform(size=(N,)),
   'y': np.random.uniform(size=(N,)),

scatter = vincent.Scatter(multi_iter2, iter_idx='x', height=100, width=200)
data = json.loads(scatter.to_json())

m = folium.Map([17.3616, 78.4747], zoom_start=10)
mk = features.Marker([17.3616, 78.4747])
p = folium.Popup('Charminar')
v = features.Vega(data, width='100%', height='100%')



Published on 27-Mar-2019 11:20:35