How to use the folium.Map function in folium

To help you get started, we’ve selected a few folium examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scikit-mobility / scikit-mobility / skmob / utils / plot.py View on Github external
if nu >= max_users:
            break
        nu += 1

        traj = df[[constants.LONGITUDE, constants.LATITUDE]]

        if max_points is None:
            di = 1
        else:
            di = max(1, len(traj) // max_points)
        traj = traj[::di]

        if nu == 1 and map_f is None:
            # initialise map
            center = list(np.median(traj, axis=0)[::-1])
            map_f = folium.Map(location=center, zoom_start=zoom, tiles=tiles)

        trajlist = traj.values.tolist()
        line = LineString(trajlist)

        if hex_color == -1:
            color = get_color(hex_color)
        else:
            color = hex_color

        tgeojson = folium.GeoJson(line,
                                  name='tgeojson',
                                  style_function=style_function(weight, color, opacity)
                                  )
        tgeojson.add_to(map_f)

        if start_end_markers:
github python-visualization / folium / tests / test_folium.py View on Github external
def setup(self):
        """Setup Folium Map."""
        with mock.patch('branca.element.uuid4') as uuid4:
            uuid4().hex = '0' * 32
            attr = 'http://openstreetmap.org'
            self.m = folium.Map(
                location=[45.5236, -122.6750],
                width=900,
                height=400,
                max_zoom=20,
                zoom_start=4,
                max_bounds=True,
                attr=attr
            )
        self.env = Environment(loader=PackageLoader('folium', 'templates'))
github bukun / book_python_gis / part010 / ch09_others / sec5_folium / test_2_data_x_x.py View on Github external
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
###############################################################################
import folium; import json
map_a = folium.Map(location=[46.3014, -123.7390],
    zoom_start=7,tiles='Stamen Terrain')
popup1 = folium.Popup(max_width=800,).add_child(
    folium.Vega(
        json.load(open('/gdata/folium/data/vis1.json')),
        width=500, height=250))
folium.RegularPolygonMarker([47.3489, -124.708],
   fill_color='#ff0000', radius=12, popup=popup1
    ).add_to(map_a)
###############################################################################
popup2 = folium.Popup(max_width=800,).add_child(
    folium.Vega(
        json.load(open('/gdata/folium/data/vis2.json')),
        width=500, height=250))
folium.RegularPolygonMarker([44.639, -124.5339],
    fill_color='#00ff00', radius=12, popup=popup2
    ).add_to(map_a)
github python-visualization / folium / tests / test_repr.py View on Github external
def m_png():
    yield folium.Map(png_enabled=True)
github python-visualization / folium / tests / plugins / test_heat_map.py View on Github external
def test_heat_map():
    np.random.seed(3141592)
    data = (np.random.normal(size=(100, 2)) * np.array([[1, 1]]) +
            np.array([[48, 5]])).tolist()
    m = folium.Map([48., 5.], tiles='stamentoner', zoom_start=6)
    hm = plugins.HeatMap(data)
    m.add_child(hm)
    m._repr_html_()

    out = normalize(m._parent.render())

    # We verify that the script import is present.
    script = ''  # noqa
    assert script in out

    # We verify that the script part is correct.
    tmpl = Template("""
            var {{this.get_name()}} = L.heatLayer(
                {{this.data}},
                {
                    minOpacity: {{this.min_opacity}},
github azavea / bus-plan / analysis / map_solver.py View on Github external
def create_basemap(df):
    """Generate a basemap"""
    center = [df['y'].mean(), df['x'].mean()]
    m = folium.Map(center, zoom_start=10, tiles='CartoDB positron')
    bounds = [[df['y'].min(), df['x'].min()], [df['y'].max(), df['x'].max()]]
    m.fit_bounds(bounds)
    return m
github luka1199 / geo-heatmap / geo_heatmap.py View on Github external
def generateMap(self, tiles, map_zoom_start=6, heatmap_radius=7,
                    heatmap_blur=4, heatmap_min_opacity=0.2,
                    heatmap_max_zoom=4):
        map_data = [(coords[0], coords[1], magnitude)
                    for coords, magnitude in self.coordinates.items()]

        # Generate map
        m = folium.Map(location=self.max_coordinates,
                       zoom_start=map_zoom_start,
                       tiles=tiles)

        # Generate heat map
        heatmap = HeatMap(map_data,
                          max_val=self.max_magnitude,
                          min_opacity=heatmap_min_opacity,
                          radius=heatmap_radius,
                          blur=heatmap_blur,
                          max_zoom=heatmap_max_zoom)

        m.add_child(heatmap)
        return m
github rdhyee / working-open-data-2014 / notebooks / Day_23_B_folium-ipython.py View on Github external
df['FIPS_Code'] = df['FIPS_Code'].astype(str)

def set_id(fips):
    '''Modify FIPS code to match GeoJSON property'''
    if fips == '0':
        return None
    elif len(fips) <= 4:
        return ''.join(['0500000US0', fips])
    else:
        return ''.join(['0500000US', fips])

#Apply set_id, drop NaN
df['GEO_ID'] = df['FIPS_Code'].apply(set_id)
df = df.dropna()

map = folium.Map(location=[40, -99], zoom_start=4)
map.geo_json(geo_path=county_geo, data_out='data2.json', data=df,
               columns=['GEO_ID', 'Unemployment_rate_2011'],
               key_on='feature.id',
               threshold_scale=[0, 5, 7, 9, 11, 13],
               fill_color='YlGnBu', line_opacity=0.3,
               legend_name='Unemployment Rate 2011 (%)',
               topojson='objects.us_counties_20m')

embed_map(map)

# 

# Blending folium with interact

# 
github javierdemartin / neural-bikes / cluster.py View on Github external
plt.title(title)
		sns.despine()
		plt.savefig(self.dir_path + "/plots/" + self.city +  "/cluster/" + str(sys.argv[1]) + "_pattern_" + type_of_analysis  + ".png")

		mask = np.logical_not(self.locations['nom'].isin(wrong_stations))

		self.locations = self.locations[mask]

		dflabel = pd.DataFrame({"label": kmeans.labels_}, index=df_norm.columns)
		

		self.locations = self.locations.merge(dflabel, right_index=True, left_on='nom')
		
		self.locations.drop_duplicates(inplace=True)

		mp = folium.Map(location=self.position, zoom_start=13, tiles='cartodbpositron')

		hex_colors = colors.as_hex()

		for _, row in self.locations.iterrows():

			folium.CircleMarker(
				location=[row['lat'], row['lon']],
				radius = 5,
				popup = row['nom'],
				color = hex_colors[row['label']],
				fill = True,
				fill_opacity = 0.5,
				foll_color = hex_colors[row['label']]
			).add_to(mp)
github python-visualization / folium / examples / antarctic_shelf.py View on Github external
'''
Map the Antarctic Ice Shelf, with normal GeoJSON and TopoJSON

'''

import folium


geo_path = r'antarctic_ice_edge.json'
topo_path = r'antarctic_ice_shelf_topo.json'

ice_map = folium.Map(location=[-59.1759, -11.6016],
                     tiles='Mapbox Bright', zoom_start=2)
ice_map.choropleth(geo_path=geo_path)
ice_map.choropleth(geo_path=topo_path, topojson='objects.antarctic_ice_shelf')
ice_map.save('map.html')