#!/usr/bin/env python # coding: utf-8 # # How to draw a *scatter* plot with folium # In[1]: import numpy as np import sys sys.path.insert(0, 'folium') sys.path.insert(0, 'branca') import branca import folium # We create a sample of data thanks to `numpy`. # In[2]: n = 100 lats = np.random.uniform(38, 53, n) lngs = np.random.uniform(-17, 23, n) sizes = np.random.uniform(2, 20, n) colors = np.random.uniform(0, 50, n) # We create a colormap thanks to `branca`. You can also create your own function or use `matplotlib`. # In[3]: cm = branca.colormap.LinearColormap(['green', 'yellow', 'red'], vmin=0, vmax=50) print(cm(25)) cm # We create a `FeatureGroup` with all the points. # In[4]: f = folium.map.FeatureGroup() for lat, lng, size, color in zip(lats, lngs, sizes, colors): f.add_child( folium.features.CircleMarker( [lat, lng], radius=size, color=None, fill_color=cm(color), fill_opacity=0.6) ) # And draw the map ! # In[5]: m = folium.Map([46,4], zoom_start=5, tiles='mapquestopen') m.add_child(f) # That's all folks !