This article is an article of Origami Advent Calendar
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.
- Mac OSX El Capitan(10.11.6)
- Python(3.5.1)
- jupyter lab(0.2.1)
$ pip install folium
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
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.
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
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.
Recommended Posts