Change marker in folium map

Leb picture Leb · Nov 6, 2015 · Viewed 15.6k times · Source

I have a script to plot multiple points on a map through folium. Is there a way to change the shape of the marker and color?

It doesn't matter if it can be done through the python code or the html file.

import folium
import json


map_osm = folium.Map(location=[37.7622, -122.4356], zoom_start=13)

geojson = {
    "type": "Feature",
    "geometry": {
        "type": "MultiPoint",
        "coordinates": [[-122.42436302145, 37.8004143219856], [-122.42699532676599, 37.80087263276921]],
    },
    "properties": {"prop0": "value0"}
}

map_osm.geo_json(geo_str=json.dumps(geojson))
map_osm.create_map(path='osm.html')

enter image description here

Answer

Collin Reinking picture Collin Reinking · May 1, 2017

Below is how I plotted with dots. I'm actually trying to put together a notebook of examples (adding color, popup, etc), although I'm still working out the kinks.

import folium
import pandas as pd

#create a map
this_map = folium.Map(prefer_canvas=True)

def plotDot(point):
    '''input: series that contains a numeric named latitude and a numeric named longitude
    this function creates a CircleMarker and adds it to your this_map'''
    folium.CircleMarker(location=[point.latitude, point.longitude],
                        radius=2,
                        weight=0).add_to(this_map)

#use df.apply(,axis=1) to "iterate" through every row in your dataframe
data.apply(plotDot, axis = 1)


#Set the zoom to the maximum possible
this_map.fit_bounds(this_map.get_bounds())

#Save the map to an HTML file
this_map.save('html_map_output/simple_dot_plot.html')

this_map

You could also use the polygon markers that this guy shows off.