It is a memorandum when visualizing prefectures with many routes by prefecture on a Japanese map.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from japanmap import pref_names,pref_code,picture
import matplotlib.pyplot as plt
from pylab import rcParams
import json
import requests
color_map = {}
num = [1]
#rcParams['figure.figsize'] = 8,8
plt.imsave("./picture.jpg ", picture({'Hokkaido':'blue','Osaka':(255,0,0),}));
# get the number of prefecture
url = 'http://express.heartrails.com/api/json?method=getPrefectures'
ret = requests.get(url)
ret_json = json.loads(ret.text)
number_of_prefectures=len(ret_json["response"]["prefecture"])
print(number_of_prefectures)
# get max number
for i in range(number_of_prefectures):
pref_name=pref_names[i+1]
url = 'http://express.heartrails.com/api/json?method=getLines&prefecture=' + pref_name
ret = requests.get(url)
ret_json = json.loads(ret.text)
num.append( len(ret_json["response"]["line"]) )
max = max( num )
print(max)
# get number of lines in all prefecture
for i in range(number_of_prefectures):
pref_name=pref_names[i+1]
url = 'http://express.heartrails.com/api/json?method=getLines&prefecture=' + pref_name
ret = requests.get(url)
ret_json = json.loads(ret.text)
print(i, pref_name, len(ret_json["response"]["line"]), ret_json["response"]["line"][0])
val = len(ret_json["response"]["line"])
color_map[pref_name] = (0, val * 255/max, 255)
plt.imsave("./result.jpg ", picture(color_map));
$ python sample-map.py
47
88
0 Hokkaido 25 JR Hakodate branch line
1 Aomori Prefecture 15 JR Gono Line
2 Iwate Prefecture 14 JR Hachinohe Line
3 Miyagi Prefecture 15 JR Senzan Line
4 Akita Prefecture 10 JR Gono Line
5 Yamagata Prefecture 9 JR Senzan Line
6 Fukushima Prefecture 13 JR Tadami Line
7 Ibaraki Prefecture 14 JR Utsunomiya Line
8 Tochigi Prefecture 15 JR Ryomo Line
9 Gunma Prefecture 16 JR Joetsu Line
10 Saitama 28 JR Keihin Tohoku Line
11 Chiba 34 JR Kururi Line
12 Tokyo 88 JR Chuo Line
13 Kanagawa 38 JR Chuo Main Line
14 Niigata 18 JR Joetsu Line
15 Toyama 17 JR Johana Line
16 Ishikawa Prefecture 8 JR Nanao Line
17 Fukui Prefecture 6 JR Hokuriku Main Line
18 Yamanashi Prefecture 4 JR Chuo Main Line
19 Nagano Prefecture 14 JR Chuo Main Line
20 Gifu Prefecture 15 JR Chuo Main Line
21 Shizuoka Prefecture 15 JR Ito Line
22 Aichi 37 JR Chuo Main Line
23 Mie Prefecture 19 JR Sangu Line
24 Shiga Prefecture 13 JR Hokuriku Main Line
25 Kyoto Prefecture 32 JR Kyoto Line
26 Osaka Prefecture 54 JR Kyoto Line
27 Hyogo Prefecture 40 JR Kakogawa Line
28 Nara Prefecture 16 JR Wakayama Line
29 Wakayama Prefecture 10 JR Wakayama Line
30 Tottori Prefecture 6 JR Hakubi Line
31 Shimane Prefecture 5 JR Yamaguchi Line
32 Okayama Prefecture 16 JR Hakubi Line
33 Hiroshima Prefecture 17 JR Kabe Line
34 Yamaguchi Prefecture 9 JR Ube Line
35 Tokushima Prefecture 6 JR Dosan Line
36 Kagawa Prefecture 8 JR Yosan Line
37 Ehime Prefecture 12 JR Yodo Line
38 Kochi Prefecture 9 JR Yodo Line
39 Fukuoka Prefecture 28 JR Kyudai Main Line
40 Saga Prefecture 9 JR Sasebo Line
41 Nagasaki Prefecture 11 JR Sasebo Line
42 Kumamoto Prefecture 15 JR Misumi Line
43 Oita Prefecture 5 JR Kyudai Main Line
44 Miyazaki Prefecture 5 JR Kitto Line
45 Kagoshima Prefecture 12 JR Kitto Line
46 Okinawa Prefecture 1 Okinawa Yui Rail
Tokyo is the most common. Next to that, there are many urban areas around Osaka and Nagoya.
Recommended Posts