[For beginners] Script within 10 lines (8. Plot map with folium [2]

[For beginners] Script within 10 lines (8. Plot map with folium [2])

If you use various libraries with python, I thought, "You can do a little thing with a little code, and you can make a little script with a little 5 steps, which is convenient." So I just listed python and other commands. I may come up with this, but I will post a 10-step script on an irregular basis.

As ** 8th **, I previously posted a script that plots a map around Ginza with markers in 3 places with folium, but in advance, set the location, latitude and longitude with csv. I prepared it and tried to plot it.

If there are many bases, this method seems to be easy to read and maintain.

In this script, I plotted the following 3 places. --Yurakucho Station: Location information [35.6749187,139.7606366] --Ginza Corridor-gai: Location information [35.6703699,139.7573871] --Ginza-SIX: Location information [35.6695908,139.7618857]

【environment】 linux: MXLinux19.1 python: 3.7.3 pip3: 20.0.2 pandas: 1.0.3 jupyter-lab: 2.1.1 folium: 0.10.1


** 1. Create a csv file with the following configuration for location information ** Place name, latitude / longitude

ginza,latitude,longtude Yurakucho_station,35.6749187,139.7606366 GinzaCorridorSteet,35.6703699,139.7573871 GinzaSix,35.66695908,139.7618857

** ・ By the way, the latitude is "latitude" and the longitude is "longtude" **, and if you search, they will be displayed in this order. As an example, in the case of Corridor-gai, it was "latitude: 35.6749187, longitude: 139.7573871". I loaded this csv with pandas.

** The minimum syntax of folium is as follows. ** ** map = folium.Map (location = [latitude, longitude of reference point], zoom_start = initial magnification) map

The code runs in jupyter and the map is plotted in jupyter.

** Example code to plot map from csv **

jupyter



#!/usr/bin/env python
# coding: utf-8
#Example of code to plot around Ginza
# infile = './map_location'
# 
#1.Library import
import folium
import pandas as pd

#read csv file
df = pd.read_csv('./map_location.csv')

#df
plot_location=df
plot_location

#Multiple point plots and marker processing read from file
map = folium.Map(location=[35.6749187,139.7606366], zoom_start = 14)
for i, r in plot_location.iterrows():
    folium.Marker(location=[r['latitude'], r['longtude']], popup=r["ginza"]).add_to(map)

# 3.Map plot
map

#df.to_csv('./map_location.csv')

ginza_map.png

Currently, it is the simplest marker, but with a little more research, it seems possible to send various information. By the way, this image is a screen capture, but it is actually possible to move or enlarge it from the plotted location.

** This is the map plot [2] in 8.folium. ** **

Recommended Posts

[For beginners] Script within 10 lines (8. Plot map with folium [2]
[For beginners] Script within 10 lines (1.folium)
[For beginners] Script within 10 lines (3. Data acquisition / csv conversion with datareader)
[For beginners] Script within 10 lines (7. Script that outputs csv from sqlite3 table with bash
[For beginners] Script within 10 lines (4. Connection from python to sqlite3)
[For beginners] Script within 10 lines (5. Resample of time series data using pandas)
Script within 10 lines (2.vimrc)
Seaborn basics for beginners ③ Scatter plot (jointplot) * With histogram
Heat Map for Grid Search with Matplotlib
Tips for plotting multiple lines with pandas
[Python] Read images with OpenCV (for beginners)
WebApi creation with Python (CRUD creation) For beginners
[For beginners] Try web scraping with Python
Pandas basics for beginners ③ Histogram creation with matplotlib
Causal reasoning and causal search with Python (for beginners)
Visualize coronavirus infection status with Plotly [For beginners]
~ Tips for Python beginners from Pythonista with love ① ~
Folium: Visualize data on a map with Python
Try drawing a map with Python's folium package
~ Tips for Python beginners from Pythonista with love ② ~
[Introduction for beginners] Working with MySQL in Python