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 ** 1st **, I would like to post a script that plots a map around Ginza in 3 places with markers using "folium (a python library that plots a map from python using leaflet). I will. 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】 LinuxMint19.3 python: 3.6.9 pip3: 9.0.1 pandas: 1.0.3 jupyter-lab: 2.1.0 folium: 0.10.1
** 1. Prepare location information ** -The location information of the place to plot was called with the map of google, and the character string of url was copied with the mouse. It was easier than checking "About this place" on google map because each place to plot geographically is close. ** ・ 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". We will store this value in each location in the data frame.
** The minimum syntax of folium is as follows. ** ** map = folium.Map (location = [latitude, longitude of reference point], zoom_start = initial magnification) map
** 2. Coding ** The code runs in jupyter and the map is plotted in jupyter.
jupyter
#Example of code to plot around Ginza
# 1.Library import
import folium
import pandas as pd
# 2.Storage of location information in data frame and processing of marker display
plot_location = pd.DataFrame({
'ginza':['Yurakucho_station','GinzaCorridorSteet','GinzaSix'],
'latitude':[35.6749187 ,35.6703699 ,35.66695908],
'longtude':[139.7606366 ,139.7573871 ,139.7618857],})
map = folium.Map(location=[35.6749187,139.7606366], zoom_start = 15)
for i, r in plot_location.iterrows():
folium.Marker(location=[r['latitude'], r['longtude']], popup=r["ginza"]).add_to(map)
# 3.Map plot
map
The map of the Ginza area is now plotted. The image below is a screen capture, but it is plotted in a jupyter notebook. Click on Corridor-gai. I think it depends on the environment, but I couldn't display it in Japanese.
The text in this pop-up is the place to place the marker, but in "2. Storage of position information in the data frame and processing of marker display", the part that describes each point corresponds. 'ginza':['Yurakucho_station','GinzaCorridorSteet','GinzaSix'],
The location information is stored in the "data frame", but if you pass it directly to folium, you can make it into a 3-line script. However, if you use a "data frame", you can prepare a data set and increase the number of bases. It seems that some of the ancestors who referred to it are stored in "csv" etc.
If you want to save the plotted map, you can output it to "html" by executing ** "save" additionally as shown below. ** **
save
#Write the plotted map in html
map.save("map_giza.html")
This "folium" is a very useful library, but it didn't work as expected depending on the environment. For reference, the following is information on the environment in which this script was executed. It is only information on the development environment, but it depends on the browser environment because it uses a web browser. In fact, some terminals weren't plotted elsewhere. I think it's probably a browser issue.
-A part of the output is deleted.
environment
less /etc/lsb-release
DISTRIB_ID=LinuxMint
DISTRIB_RELEASE=19.3
DISTRIB_DESCRIPTION="Linux Mint 19.3 Tricia"
(py3_env) $ pip3 --version
pip 9.0.1 from /home/xxx/py3_env/lib/python3.6/site-packages (python 3.6)
(py3_env)$ python -V
Python 3.6.9
$ pip3 show pandas
Name: pandas
Version: 1.0.3
Home-page: https://pandas.pydata.org
Requires: python-dateutil, pytz, numpy
(py3_env)$ pip3 show jupyterlab
Name: jupyterlab
Version: 2.1.0
Home-page: http://jupyter.org
Requires: notebook, tornado, jinja2, jupyterlab-server
(py3_env)$ pip3 show folium
Name: folium
Version: 0.10.1
Home-page: https://github.com/python-visualization/folium
Requires: numpy, jinja2, requests, branca
** The above is a map plot using folium. ** **
Recommended Posts