or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

core-mapping.mddata-visualization.mdindex.mdinteractive-features.mdplugins.mdutilities-styling.mdvector-layers.md
tile.json

tessl/pypi-folium

Make beautiful maps with Leaflet.js & Python

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/folium@0.20.x

To install, run

npx @tessl/cli install tessl/pypi-folium@0.20.0

index.mddocs/

Folium

A comprehensive Python library for creating interactive web maps with Leaflet.js. Folium enables data scientists and developers to visualize geospatial data through Python's data manipulation capabilities while leveraging the powerful mapping features of the Leaflet.js JavaScript library. It offers a complete set of mapping components including markers, polygons, circles, popups, tooltips, choropleth maps, and various tile layers, with support for GeoJSON data integration, custom styling, and interactive features.

Package Information

  • Package Name: folium
  • Language: Python
  • Installation: pip install folium

Core Imports

import folium

Common patterns for specific functionality:

from folium import Map, Marker, Popup, Icon
from folium import GeoJson, Choropleth, FeatureGroup
from folium.vector_layers import PolyLine, Polygon, Circle
from folium.plugins import MarkerCluster, HeatMap

Basic Usage

import folium
import numpy as np

# Create a basic map
map = folium.Map(
    location=[45.5236, -122.6750],  # Portland, OR
    zoom_start=13,
    tiles='OpenStreetMap'
)

# Add a simple marker
folium.Marker(
    [45.5244, -122.6699],
    popup='Downtown Portland',
    tooltip='Click me!',
    icon=folium.Icon(color='red', icon='info-sign')
).add_to(map)

# Add a circle
folium.Circle(
    location=[45.5236, -122.6750],
    radius=300,
    popup='300m radius',
    color='blue',
    fill=True,
    fillColor='lightblue'
).add_to(map)

# Display map (in Jupyter) or save
map.save('my_map.html')

Architecture

Folium is built around a hierarchical component system:

  • Map: The root container managing canvas, layers, and overall layout
  • Layers: Raster (tiles) and vector (shapes) data layers
  • Features: Interactive elements like markers, popups, and data visualizations
  • Controls: UI elements for layer management and user interaction
  • Plugins: Extended functionality through 40 specialized plugins

This design allows every visual element to be customized and provides seamless integration with Python data science libraries including NumPy, pandas, GeoPandas, and Jupyter notebooks.

Capabilities

Core Mapping

The fundamental Map class and essential mapping components including tile layers, basic markers, popups, and layer management controls.

class Map:
    def __init__(
        self,
        location=None,
        width='100%',
        height='100%',
        left='0%',
        top='0%',
        position='relative',
        tiles='OpenStreetMap',
        attr=None,
        min_zoom=0,
        max_zoom=18,
        zoom_start=10,
        min_lat=-90,
        max_lat=90,
        min_lon=-180,
        max_lon=180,
        max_bounds=False,
        crs='EPSG3857',
        control_scale=False,
        prefer_canvas=False,
        no_touch=False,
        disable_3d=False,
        png_enabled=False,
        zoom_control=True,
        **kwargs
    ): ...

class Marker:
    def __init__(
        self,
        location=None,
        tooltip=None,
        popup=None,
        icon=None,
        draggable=False,
        **kwargs
    ): ...

class TileLayer:
    def __init__(
        self,
        tiles='OpenStreetMap',
        min_zoom=0,
        max_zoom=18,
        max_native_zoom=None,
        attr=None,
        name=None,
        overlay=False,
        control=True,
        show=True,
        **kwargs
    ): ...

Core Mapping

Data Visualization

Advanced data visualization capabilities including GeoJSON rendering, choropleth maps, and integration with Vega/Vega-Lite for embedded charts.

class GeoJson:
    def __init__(
        self,
        data,
        style_function=None,
        highlight_function=None,
        name=None,
        overlay=True,
        control=True,
        show=True,
        smooth_factor=1.0,
        tooltip=None,
        popup=None,
        marker=None,
        **kwargs
    ): ...

class Choropleth:
    def __init__(
        self,
        geo_data,
        data=None,
        columns=None,
        key_on=None,
        bins=6,
        fill_color='blue',
        nan_fill_color='black',
        fill_opacity=0.7,
        nan_fill_opacity=0.4,
        line_color='black',
        line_weight=1,
        line_opacity=1,
        name=None,
        legend_name='',
        overlay=True,
        control=True,
        show=True,
        topojson=None,
        smooth_factor=1.0,
        highlight=False,
        **kwargs
    ): ...

Data Visualization

Vector Layers

Geometric shapes and paths including polylines, polygons, circles, and rectangles with customizable styling and interactive features.

class PolyLine:
    def __init__(
        self,
        locations,
        popup=None,
        tooltip=None,
        smooth_factor=1.0,
        no_clip=False,
        **kwargs
    ): ...

class Polygon:
    def __init__(
        self,
        locations,
        popup=None,
        tooltip=None,
        **kwargs
    ): ...

class Circle:
    def __init__(
        self,
        location=None,
        radius=10,
        popup=None,
        tooltip=None,
        **kwargs
    ): ...

Vector Layers

Interactive Features

User interaction components including click handlers, custom controls, and specialized marker types for enhanced map interactivity.

class ClickForMarker:
    def __init__(self, popup=None): ...

class ClickForLatLng:
    def __init__(self, format_str=None, alert=False): ...

class Control:
    def __init__(self, position='topright'): ...

Interactive Features

Plugins

Extensive plugin ecosystem providing specialized functionality including clustering, heatmaps, drawing tools, temporal visualizations, and advanced controls.

class MarkerCluster:
    def __init__(
        self,
        locations=None,
        popups=None,
        tooltips=None,
        icons=None,
        name=None,
        overlay=True,
        control=True,
        show=True,
        icon_create_function=None,
        options=None
    ): ...

class HeatMap:
    def __init__(
        self,
        data,
        name=None,
        min_opacity=0.4,
        max_zoom=18,
        max_val=1.0,
        radius=25,
        blur=15,
        gradient=None,
        overlay=True,
        control=True,
        show=True
    ): ...

class Draw:
    def __init__(
        self,
        export=False,
        filename='data.geojson',
        position='topleft',
        draw_options=None,
        edit_options=None
    ): ...

Plugins

Utilities and Styling

Helper functions, color maps, and JavaScript integration utilities for advanced customization and programmatic map control.

class JsCode:
    def __init__(self, js_code): ...

class ColorMap:
    def __init__(self, colors, index=None, vmin=0, vmax=1, caption=''): ...

class LinearColormap:
    def __init__(
        self,
        colors,
        index=None,
        vmin=0,
        vmax=1,
        caption=''
    ): ...

Utilities and Styling

Types

# Location types
Location = Union[Tuple[float, float], List[float]]
Locations = Union[List[Location], Tuple[Location, ...]]

# Bounds type  
Bounds = Union[List[List[float]], Tuple[Tuple[float, float], Tuple[float, float]]]

# Style function type
StyleFunction = Callable[[Dict], Dict[str, Any]]

# GeoJSON-like data
GeoJsonData = Union[Dict, str, FeatureCollection]