Convert Figma logo to code with AI

python-visualization logofolium

Python Data. Leaflet.js Maps.

7,206
2,246
7,206
74

Top Related Projects

17,541

The interactive graphing library for Python :sparkles:

20,001

Interactive Data Visualization in the browser, from Python

Python tools for geographic data

matplotlib: plotting with Python

43,292

πŸƒ JavaScript library for mobile-friendly interactive maps πŸ‡ΊπŸ‡¦

10,879

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

Quick Overview

Folium is a Python library that allows you to create interactive and customizable maps using the Leaflet.js mapping library. It provides a Pythonic interface to generate HTML and JavaScript code for map visualization, making it easy to integrate maps into web applications or Jupyter notebooks.

Pros

  • Easy to use with a simple, intuitive API
  • Supports various map tile providers and custom overlays
  • Integrates well with pandas and geopandas for data visualization
  • Generates standalone HTML files for easy sharing and embedding

Cons

  • Limited advanced customization options compared to pure JavaScript libraries
  • Performance can be slow with large datasets
  • Documentation could be more comprehensive and up-to-date
  • Lacks some features available in more specialized mapping libraries

Code Examples

Creating a simple map:

import folium

m = folium.Map(location=[45.5236, -122.6750], zoom_start=13)
m.save("map.html")

Adding markers and popups:

m = folium.Map(location=[45.5236, -122.6750], zoom_start=13)
folium.Marker(
    [45.5236, -122.6750],
    popup="Portland, Oregon",
    tooltip="Click for more info"
).add_to(m)
m.save("map_with_marker.html")

Creating a choropleth map:

import folium
import pandas as pd

# Assuming you have a GeoJSON file and a DataFrame with data
geo_data = "us-states.json"
state_data = pd.read_csv("state_data.csv")

m = folium.Map(location=[37, -102], zoom_start=4)
folium.Choropleth(
    geo_data=geo_data,
    name="choropleth",
    data=state_data,
    columns=["State", "Unemployment"],
    key_on="feature.id",
    fill_color="YlOrRd",
    fill_opacity=0.7,
    line_opacity=0.2,
    legend_name="Unemployment Rate (%)"
).add_to(m)

folium.LayerControl().add_to(m)
m.save("choropleth_map.html")

Getting Started

To get started with Folium, first install it using pip:

pip install folium

Then, you can create a simple map with just a few lines of code:

import folium

m = folium.Map(location=[51.509, -0.118], zoom_start=13)
folium.Marker([51.509, -0.118], popup="London").add_to(m)
m.save("london_map.html")

This will create an HTML file with an interactive map centered on London with a marker. Open the HTML file in a web browser to view the map.

Competitor Comparisons

17,541

The interactive graphing library for Python :sparkles:

Pros of Plotly

  • More diverse chart types and advanced visualizations
  • Interactive features like zooming, panning, and hover tooltips
  • Supports both static and dynamic data updates

Cons of Plotly

  • Steeper learning curve compared to Folium
  • Larger file sizes for interactive visualizations
  • Requires JavaScript for full functionality

Code Comparison

Folium (creating a simple map):

import folium

m = folium.Map(location=[45.5236, -122.6750])
folium.Marker([45.5236, -122.6750], popup="Portland, OR").add_to(m)
m.save("map.html")

Plotly (creating a simple map):

import plotly.graph_objects as go

fig = go.Figure(go.Scattermapbox(
    lat=[45.5236],
    lon=[-122.6750],
    mode='markers',
    marker=go.scattermapbox.Marker(size=14),
    text=["Portland, OR"],
))

fig.update_layout(mapbox_style="open-street-map")
fig.show()

Both libraries offer mapping capabilities, but Plotly provides more customization options and interactive features, while Folium is simpler to use for basic maps. Plotly's code is more verbose but offers greater flexibility in styling and data representation.

20,001

Interactive Data Visualization in the browser, from Python

Pros of Bokeh

  • More versatile for creating interactive visualizations beyond just maps
  • Supports server-side rendering for handling large datasets
  • Offers a wider range of customizable chart types and widgets

Cons of Bokeh

  • Steeper learning curve compared to Folium
  • Requires more code to create basic maps
  • Less focused on geospatial visualizations

Code Comparison

Folium (creating a simple map):

import folium
m = folium.Map(location=[45.5236, -122.6750])
m.save("map.html")

Bokeh (creating a simple map):

from bokeh.io import show
from bokeh.plotting import figure
from bokeh.tile_providers import CARTODBPOSITRON

p = figure(x_range=(-2000000, 6000000), y_range=(-1000000, 7000000),
           x_axis_type="mercator", y_axis_type="mercator")
p.add_tile(CARTODBPOSITRON)
show(p)

Folium is more concise for creating maps, while Bokeh requires more setup but offers greater flexibility for various visualization types.

Python tools for geographic data

Pros of GeoPandas

  • Powerful data manipulation capabilities for geospatial data
  • Integrates well with pandas for complex data analysis
  • Supports a wide range of geospatial file formats

Cons of GeoPandas

  • Less interactive and web-friendly than Folium
  • Steeper learning curve for users new to GIS concepts
  • Limited built-in visualization options compared to Folium

Code Comparison

GeoPandas example:

import geopandas as gpd
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
world.plot()

Folium example:

import folium
m = folium.Map(location=[0, 0], zoom_start=2)
folium.GeoJson(world).add_to(m)
m

GeoPandas excels in data manipulation and analysis of geospatial data, while Folium focuses on creating interactive web maps. GeoPandas is better suited for complex GIS operations and working with various geospatial formats. Folium, on the other hand, provides an easier way to create interactive maps for web applications. The choice between the two depends on the specific requirements of your project, such as the need for data analysis versus interactive visualization.

matplotlib: plotting with Python

Pros of matplotlib

  • More comprehensive and versatile for creating various types of static plots
  • Extensive documentation and large community support
  • Fine-grained control over plot elements and customization

Cons of matplotlib

  • Steeper learning curve for beginners
  • Less suitable for interactive or web-based visualizations
  • Requires more code to create basic plots compared to Folium

Code Comparison

matplotlib:

import matplotlib.pyplot as plt

plt.plot([1, 2, 3, 4], [1, 4, 2, 3])
plt.title('Simple Line Plot')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.show()

Folium:

import folium

m = folium.Map(location=[45.5236, -122.6750], zoom_start=13)
folium.Marker([45.5236, -122.6750], popup='Portland, OR').add_to(m)
m.save('map.html')

Matplotlib excels in creating static, publication-quality plots with extensive customization options, while Folium specializes in interactive maps and geospatial visualizations. Matplotlib requires more code for basic plots but offers greater flexibility, whereas Folium provides a simpler API for creating interactive maps with less code.

43,292

πŸƒ JavaScript library for mobile-friendly interactive maps πŸ‡ΊπŸ‡¦

Pros of Leaflet

  • Direct JavaScript implementation, offering more flexibility and control
  • Extensive plugin ecosystem for advanced features
  • Better performance for large datasets and complex visualizations

Cons of Leaflet

  • Requires JavaScript knowledge, which may be challenging for Python-focused developers
  • More setup and configuration needed compared to Folium's Python-based approach
  • Less integrated with data analysis workflows in Python environments

Code Comparison

Leaflet (JavaScript):

var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
L.marker([51.5, -0.09]).addTo(map)
    .bindPopup('A sample marker.')
    .openPopup();

Folium (Python):

import folium
m = folium.Map(location=[51.505, -0.09], zoom_start=13)
folium.Marker([51.5, -0.09], popup='A sample marker.').add_to(m)
m.save('map.html')

Summary

Leaflet is a powerful JavaScript library for interactive maps, offering more flexibility and performance but requiring JavaScript expertise. Folium, built on top of Leaflet, provides a Python-friendly interface, making it easier for Python developers to create maps within their existing workflows, albeit with some limitations in advanced customization.

10,879

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

Pros of Kepler.gl

  • More advanced and interactive visualization capabilities
  • Supports larger datasets with better performance
  • Offers a wider range of map styles and layer types

Cons of Kepler.gl

  • Steeper learning curve and more complex setup
  • Less integration with Python ecosystem
  • Requires more computational resources

Code Comparison

Folium example:

import folium

m = folium.Map(location=[45.5236, -122.6750])
folium.Marker([45.5236, -122.6750], popup="Portland, OR").add_to(m)
m.save("map.html")

Kepler.gl example:

from keplergl import KeplerGl

map_1 = KeplerGl(height=400, data={"data_1": df})
map_1.save_to_html(file_name="kepler_map.html")

Both libraries offer ways to create interactive maps, but Kepler.gl provides more advanced features and customization options at the cost of increased complexity. Folium is more straightforward and integrates well with the Python ecosystem, making it easier for beginners or simpler mapping tasks. Kepler.gl excels in handling larger datasets and creating more sophisticated visualizations, but may require more setup and resources.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

|PyPI| |Test| |Gitter| |DOI| |binder|

.. |PyPI| image:: https://img.shields.io/pypi/v/folium.svg :target: https://pypi.org/project/folium :alt: PyPI Package

.. |Test| image:: https://github.com/python-visualization/folium/actions/workflows/test_code.yml/badge.svg :target: https://github.com/python-visualization/folium/actions/workflows/test_code.yml :alt: Code tests

.. |Gitter| image:: https://badges.gitter.im/python-visualization/folium.svg :target: https://gitter.im/python-visualization/folium :alt: Gitter

.. |DOI| image:: https://zenodo.org/badge/18669/python-visualization/folium.svg :target: https://zenodo.org/badge/latestdoi/18669/python-visualization/folium :alt: DOI

.. |binder| image:: https://mybinder.org/badge_logo.svg :target: https://mybinder.org/v2/gh/python-visualization/folium/main?filepath=examples

folium

.. image:: https://github.com/python-visualization/folium/blob/main/docs/_static/folium_logo.png :height: 100px

Python Data, Leaflet.js Maps


`folium` builds on the data wrangling strengths of the Python ecosystem and the
mapping strengths of the Leaflet.js library. Manipulate your data in Python,
then visualize it in a Leaflet map via `folium`.

Installation
------------

.. code:: bash

    $ pip install folium

or

.. code:: bash

    $ conda install -c conda-forge folium

Documentation
-------------

https://python-visualization.github.io/folium/latest/


Contributing
------------

We love contributions!  folium is open source, built on open source,
and we'd love to have you hang out in our community.

See `our complete contributor's guide <https://github.com/python-visualization/folium/blob/main/.github/CONTRIBUTING.md>`_ for more info.


Changelog
---------

- Release notes of v0.16.0 and higher: https://github.com/python-visualization/folium/releases
- Older `changelog <https://raw.githubusercontent.com/python-visualization/folium/main/CHANGES.txt>`_


Packages and plugins
--------------------

Packages:

- https://github.com/geopandas/xyzservices: a repository of raster basemap tilesets.
- https://github.com/randyzwitch/streamlit-folium: run folium in a Streamlit app.
- https://github.com/FEMlium/FEMlium: interactive visualization of finite element simulations on geographic maps with folium.

Plugins:

- https://github.com/onaci/folium-glify-layer: provide fast webgl rendering for large GeoJSON FeatureCollections
- https://github.com/carlosign/Folium.ControlCredits-Plugin: displaying credits in the corner. Display an image/logo, clicking it will expand to show a brief message with credits and links.
- https://github.com/JohnyCarrot/folium-geocoder-own-locations: a geocoder that accepts a list of suggestions at creation time.
- https://github.com/iwpnd/folium-vectortilelayer: a tile layer that zooms and stretches beyond the maximum and minimum of the tile provider