Data visualization library "folium" by Python is very easy to use

This article is an article of Origami Advent Calendar

Overview

You may often hear that the method of Data Visualization by Python uses matplotlib or seaborn, but this time I would like to introduce a library called "folium".

folium is a library of data visualization using JavaScript OSS called leaflet, and has the advantage of many expressions using maps.

Therefore, if you want to output a bar graph, histogram, or scatter plot, it is better to use matplotlib or seaborn as appropriate, but for data with location information, folium is an option (affirmation).

Then, I will introduce what you can do with folium.

environment

- Mac OSX El Capitan(10.11.6)
- Python(3.5.1)
- jupyter lab(0.2.1)

Installation

$ pip install folium

Show map

First, let's display the map. In folium.Map, the options use location and zoom_start, but there are other tiles (change the appearance of the map), such as Stamen Toner and Stamen Terrain. ..

folium-sample1.py


import folium
m = folium.Map(location=[35.681382, 139.76608399999998], zoom_start=14) #Latitude and longitude of Tokyo station
m
Screen Shot 2016-12-27 at 10.38.21.png

Plot points on the map

First, paste the code.

folium-sample2.py


import folium

m = folium.Map(location=[35.681382, 139.76608399999998], zoom_start=12)

folium.Marker([35.658581, 139.745433], popup='Tokyo tower', icon=folium.Icon(color='blue')).add_to(m)
folium.Marker([35.710063, 139.8107], popup='Tokyo skytree', icon=folium.Icon(color='blue', icon='cloud')).add_to(m)

m

You can plot like a map by adding Maker to the map prepared earlier. Options are

-popup: leave a comment --color: Color the Maker --icon: Iconize Maker

Icon uses fontawesome and defaults to ʻinfo-sign` I have. Also, the default colors and the corresponding colors are listed here.

Screen Shot 2016-12-27 at 10.52.36.png

Plot circles on a map

You can draw a circle on the map by using CircleMarker. The unit of radius can be set to m, color or fil color.

folium-sample3.py


import folium

m = folium.Map(location=[35.681382, 139.76608399999998], zoom_start=12)

folium.Marker([35.658581, 139.745433], popup='Tokyo tower', icon=folium.Icon(color='blue')).add_to(m)
folium.Marker([35.710063, 139.8107], popup='Tokyo skytree', icon=folium.Icon(color='blue', icon='bookmark')).add_to(m)

folium.CircleMarker(
    location=[35.681382, 139.76608399999998],
    radius=2000,
    popup='Tokyo Station',
    color='#3186cc',
    fill_color='#3186cc'
).add_to(m)
m
Screen Shot 2016-12-27 at 11.17.53.png

Summary

Only a part of the functions are introduced here, but for example, it is easy to store the clustering result in pandas.Dataframe or numpy.array and display it on a map, so location information If you are doing data analysis related to, please use it. There are many examples in folium, so you can enjoy trying data visualization.

Link

Recommended Posts

Data visualization library "folium" by Python is very easy to use
How to use Requests (Python Library)
Easy to use Jupyter notebook (Python3.5)
Easy data visualization with Python seaborn.
Easy way to use Wikipedia in Python
How to use "deque" for Python data
How to use is and == in Python
Python is easy
How to use folium (visualization of location information)
Easy way to use Python 2.7 on Cent OS 6
How to use Python Image Library in python3 series
Visualization memo by Python
Python Data Visualization Libraries
Easy to use Flask
I wanted to use the Python library from MATLAB
[Python] How to use the graph creation library Altair
Easy to use SQLite3
Re: Python lambda is useless ^ H ^ H ^ H ^ H ^ H Difficult to use
Easy to use Nifty Cloud API with botocore and python
[python] How to use the library Matplotlib for drawing graphs
Five useful Python data types that are easy to forget
[Python] An easy way to visualize energy data interactively [plotly.express]
Pass OpenCV data from the original C ++ library to Python
python3: How to use bottle (2)
[Python] How to use list 1
Python is painful. But use
Visualization of data by prefecture
How to use Python argparse
Python application: data visualization # 2: matplotlib
Python: How to use pydub
[Python] How to use checkio
Easy to use E-Cell 4 Intermediate
[Python] How to use input ()
How to use Python lambda
[Python] How to use virtualenv
python3: How to use bottle (3)
python3: How to use bottle
How to use Python bytes
processing to use notMNIST data in Python (and tried to classify it)
How to use the asterisk (*) in Python. Maybe this is all? ..
[pepper] Pass the JSON data obtained by python request to the tablet.
Impressions of touching Dash, a data visualization tool made by python
If Python code written by someone else is hard to decipher (Python)
Easy to use E-Cell 4 Beginner's edition
Use pymol as a python library
[Python] How to FFT mp3 data
Python: How to use async with
Easy way to customize Python import
Introduction to Python Numerical Library NumPy
Use fabric as is in python (fabric3)
[Python] How to use Pandas Series
How to use SQLite in Python
Proper use of Python visualization packages
Easy visualization using Python but PixieDust
[Python] How to import the library
[Introduction to Python] Let's use pandas
[Python] How to use list 3 Added
Bayesian optimization very easy with Python
How to use Mysql in python
How to use OpenPose's Python API
How to use ChemSpider in Python