Skip to content

Instantly share code, notes, and snippets.

@y-mitsui
Last active April 10, 2019 04:46
Show Gist options
  • Select an option

  • Save y-mitsui/6b87916aaa47d66caa7c to your computer and use it in GitHub Desktop.

Select an option

Save y-mitsui/6b87916aaa47d66caa7c to your computer and use it in GitHub Desktop.
matplotlibで都道府県地図を描画
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
matplotlibで都道府県地図を描画
"""
import matplotlib.path as mpath
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
from matplotlib.patches import Circle, Wedge, Polygon
from matplotlib.collections import PatchCollection
import matplotlib
import numpy as np
from pylab import text
Path = mpath.Path
path_datas = [
#北海道
[
(Path.MOVETO, (568, 870)),
(Path.LINETO, (543, 739)),
(Path.LINETO, (586, 739)),
(Path.LINETO, (588, 760)),
(Path.LINETO, (717, 761)),
(Path.LINETO, (736, 869)),
(Path.LINETO, (568, 870)),
],
#青森
[
(Path.MOVETO, (541, 722)),
(Path.LINETO, (535, 690)),
(Path.LINETO, (665, 690)),
(Path.LINETO, (671, 722)),
(Path.LINETO, (541, 722)),
],
#岩手
[
(Path.MOVETO, (601, 688)),
(Path.LINETO, (594, 643)),
(Path.LINETO, (657, 644)),
(Path.LINETO, (665, 688)),
(Path.LINETO, (601, 688)),
],
#宮城
[
(Path.MOVETO, (593, 640)),
(Path.LINETO, (585, 590)),
(Path.LINETO, (648, 590)),
(Path.LINETO, (657, 640)),
(Path.LINETO, (593, 640)),
],
#秋田
[
(Path.MOVETO, (535, 687)),
(Path.LINETO, (527, 644)),
(Path.LINETO, (591, 643)),
(Path.LINETO, (598, 687)),
(Path.LINETO, (535, 687)),
],
#山形
[
(Path.MOVETO, (526, 641)),
(Path.LINETO, (520, 606)),
(Path.LINETO, (547, 606)),
(Path.LINETO, (544, 590)),
(Path.LINETO, (582, 590)),
(Path.LINETO, (590, 641)),
(Path.LINETO, (526, 641)),
],
#福島
[
(Path.MOVETO, (544, 588)),
(Path.LINETO, (537, 545)),
(Path.LINETO, (641, 545)),
(Path.LINETO, (648, 589)),
(Path.LINETO, (544, 588)),
],
#茨城
[
(Path.MOVETO, (602, 543)),
(Path.LINETO, (590, 477)),
(Path.LINETO, (629, 477)),
(Path.LINETO, (640, 543)),
(Path.LINETO, (602, 543)),
],
#栃木
[
(Path.MOVETO, (556, 544)),
(Path.LINETO, (548, 494)),
(Path.LINETO, (592, 494)),
(Path.LINETO, (600, 543)),
(Path.LINETO, (556, 544)),
],
#群馬
[
(Path.MOVETO, (509, 543)),
(Path.LINETO, (501, 494)),
(Path.LINETO, (546, 494)),
(Path.LINETO, (554, 543)),
(Path.LINETO, (509, 543)),
],
#埼玉
[
(Path.MOVETO, (501, 492 )),
(Path.LINETO, (494, 448)),
(Path.LINETO, (584, 448)),
(Path.LINETO, (591, 492)),
(Path.LINETO, (501, 492)),
],
#千葉
[
(Path.MOVETO, (590, 474)),
(Path.LINETO, (571, 361)),
(Path.LINETO, (610, 361)),
(Path.LINETO, (629, 474)),
(Path.LINETO, (590, 474)),
],
#東京
[
(Path.MOVETO, (520, 447 )),
(Path.LINETO, (513, 411)),
(Path.LINETO, (557, 410)),
(Path.LINETO, (559, 420)),
(Path.LINETO, (579, 420)),
(Path.LINETO, (584, 447)),
(Path.LINETO, (520, 447)),
],
#神奈川
[
(Path.MOVETO, (487, 409 )),
(Path.LINETO, (482, 382)),
(Path.LINETO, (509, 382)),
(Path.LINETO, (508, 375)),
(Path.LINETO, (551, 375)),
(Path.LINETO, (557, 409)),
(Path.LINETO, (487, 409)),
],
#新潟
[
(Path.MOVETO, (521, 607)),
(Path.LINETO, (517, 590)),
(Path.LINETO, (488, 590)),
(Path.LINETO, (480, 546)),
(Path.LINETO, (537, 545)),
(Path.LINETO, (547, 606)),
(Path.LINETO, (521, 607)),
],
#富山
[
(Path.MOVETO, (443, 590)),
(Path.LINETO, (436, 544)),
(Path.LINETO, (479, 544)),
(Path.LINETO, (486, 590)),
(Path.LINETO, (443, 590)),
],
#石川
[
(Path.MOVETO, (417, 618)),
(Path.LINETO, (404, 545)),
(Path.LINETO, (434, 544)),
(Path.LINETO, (447, 618)),
(Path.LINETO, (417, 618)),
],
#福井
[
(Path.MOVETO, (404, 543)),
(Path.LINETO, (400, 520)),
(Path.LINETO, (373, 520)),
(Path.LINETO, (369, 493)),
(Path.LINETO, (424, 493)),
(Path.LINETO, (433, 542)),
(Path.LINETO, (404, 543)),
],
#山梨
[
(Path.MOVETO, (479, 447 )),
(Path.LINETO, (471, 410)),
(Path.LINETO, (512, 410)),
(Path.LINETO, (518, 447)),
(Path.LINETO, (479, 447)),
],
#長野
[
(Path.MOVETO, (470, 543)),
(Path.LINETO, (447, 410)),
(Path.LINETO, (470, 410)),
(Path.LINETO, (477, 449)),
(Path.LINETO, (492, 449)),
(Path.LINETO, (508, 543)),
(Path.LINETO, (470, 543)),
],
#岐阜
[
(Path.MOVETO, (435, 543)),
(Path.LINETO, (411, 410)),
(Path.LINETO, (446, 410)),
(Path.LINETO, (469, 543)),
(Path.LINETO, (435, 543)),
],
#静岡
[
(Path.MOVETO, (458, 409)),
(Path.LINETO, (449, 359)),
(Path.LINETO, (504, 359)),
(Path.LINETO, (508, 381)),
(Path.LINETO, (480, 380)),
(Path.LINETO, (486, 409)),
(Path.LINETO, (458, 409)),
],
#愛知
[
(Path.MOVETO, (411, 409)),
(Path.LINETO, (402, 359)),
(Path.LINETO, (447, 359)),
(Path.LINETO, (456, 409)),
(Path.LINETO, (411, 409)),
],
#三重
[
(Path.MOVETO, (389, 447)),
(Path.LINETO, (370, 332)),
(Path.LINETO, (398, 332)),
(Path.LINETO, (416, 447)),
(Path.LINETO, (389, 447)),
],
#滋賀
[
(Path.MOVETO, (396, 491)),
(Path.LINETO, (389, 449)),
(Path.LINETO, (416, 449)),
(Path.LINETO, (424, 491)),
(Path.LINETO, (396, 491)),
],
#京都
[
(Path.MOVETO, (344, 520)),
(Path.LINETO, (332, 450)),
(Path.LINETO, (387, 449)),
(Path.LINETO, (395, 491)),
(Path.LINETO, (367, 491)),
(Path.LINETO, (370, 520)),
(Path.LINETO, (344, 520)),
],
#大阪
[
(Path.MOVETO, (332, 447)),
(Path.LINETO, (322, 384)),
(Path.LINETO, (348, 384)),
(Path.LINETO, (359, 447)),
(Path.LINETO, (332, 447)),
],
#兵庫
[
(Path.MOVETO, (311, 520)),
(Path.LINETO, (294, 421)),
(Path.LINETO, (326, 422)),
(Path.LINETO, (343, 520)),
(Path.LINETO, (311, 520)),
],
#奈良
[
(Path.MOVETO, (361, 447)),
(Path.LINETO, (346, 361)),
(Path.LINETO, (372, 361)),
(Path.LINETO, (387, 447)),
(Path.LINETO, (361, 447)),
],
#和歌山
[
(Path.MOVETO, (322, 382)),
(Path.LINETO, (314, 332)),
(Path.LINETO, (368, 332)),
(Path.LINETO, (372, 359)),
(Path.LINETO, (344, 359)),
(Path.LINETO, (348, 382)),
(Path.LINETO, (322, 382)),
],
#鳥取
[
(Path.MOVETO, (276, 520)),
(Path.LINETO, (268, 475)),
(Path.LINETO, (301, 475)),
(Path.LINETO, (309, 520)),
(Path.LINETO, (276, 520)),
],
#島根
[
(Path.MOVETO, (242, 520)),
(Path.LINETO, (234, 475)),
(Path.LINETO, (267, 475)),
(Path.LINETO, (274, 520)),
(Path.LINETO, (242, 520)),
],
#岡山
[
(Path.MOVETO, (268, 473)),
(Path.LINETO, (259, 422)),
(Path.LINETO, (293, 422)),
(Path.LINETO, (302, 473)),
(Path.LINETO, (268, 473)),
],
#広島
[
(Path.MOVETO, (234, 474)),
(Path.LINETO, (225, 421)),
(Path.LINETO, (257, 422)),
(Path.LINETO, (266, 473)),
(Path.LINETO, (234, 474)),
],
#山口
[
(Path.MOVETO, (210, 520)),
(Path.LINETO, (193, 421)),
(Path.LINETO, (223, 422)),
(Path.LINETO, (240, 520)),
(Path.LINETO, (210, 520)),
],
#徳島
[
(Path.MOVETO, (244, 369)),
(Path.LINETO, (238, 334)),
(Path.LINETO, (299, 334)),
(Path.LINETO, (305, 369)),
(Path.LINETO, (244, 369)),
],
#香川
[
(Path.MOVETO, (250, 406)),
(Path.LINETO, (244, 371)),
(Path.LINETO, (306, 371)),
(Path.LINETO, (311, 405)),
(Path.LINETO, (250, 406)),
],
#愛媛
[
(Path.MOVETO, (189, 405)),
(Path.LINETO, (184, 371)),
(Path.LINETO, (243, 371)),
(Path.LINETO, (248, 406)),
(Path.LINETO, (189, 405)),
],
#高知
[
(Path.MOVETO, (184, 369)),
(Path.LINETO, (177, 335)),
(Path.LINETO, (236, 334)),
(Path.LINETO, (242, 369)),
(Path.LINETO, (184, 369)),
],
#福岡
[
(Path.MOVETO, (120, 521)),
(Path.LINETO, (112, 475)),
(Path.LINETO, (184, 475)),
(Path.LINETO, (192, 521)),
(Path.LINETO, (120, 521)),
],
#佐賀
[
(Path.MOVETO, (97, 521)),
(Path.LINETO, (86, 463)),
(Path.LINETO, (108, 463)),
(Path.LINETO, (118, 521)),
(Path.LINETO, (97, 521)),
],
#長崎
[
(Path.MOVETO, (73, 521)),
(Path.LINETO, (63, 463)),
(Path.LINETO, (84, 463)),
(Path.LINETO, (94, 521)),
(Path.LINETO, (73, 521)),
],
#熊本
[
(Path.MOVETO, (112, 473)),
(Path.LINETO, (97, 385)),
(Path.LINETO, (126, 385)),
(Path.LINETO, (141, 473)),
(Path.LINETO, (112, 473)),
],
#大分
[
(Path.MOVETO, (143, 473)),
(Path.LINETO, (136, 429)),
(Path.LINETO, (176, 429)),
(Path.LINETO, (183, 473)),
(Path.LINETO, (143, 473)),
],
#宮崎
[
(Path.MOVETO, (136, 427)),
(Path.LINETO, (129, 385)),
(Path.LINETO, (169, 385)),
(Path.LINETO, (175, 426)),
(Path.LINETO, (136, 427)),
],
#鹿児島
[
(Path.MOVETO, (96, 383)),
(Path.LINETO, (88, 334)),
(Path.LINETO, (160, 334)),
(Path.LINETO, (168, 383)),
(Path.LINETO, (96, 383)),
],
#沖縄
[
(Path.MOVETO, (51, 384)),
(Path.LINETO, (43, 334)),
(Path.LINETO, (71, 334)),
(Path.LINETO, (79, 384)),
(Path.LINETO, (51, 384)),
]
]
fig, ax = plt.subplots()
ax.set_xlim([0, 800])
ax.set_ylim([300, 900])
patches = []
for path_data in path_datas:
codes, verts = zip(*path_data)
path = mpath.Path(verts, codes)
patch = mpatches.PathPatch(path)
patches.append(patch)
p = PatchCollection(patches, cmap=matplotlib.cm.YlOrRd, alpha=0.8)
colors = 100*np.random.rand(len(patches))
p.set_array(np.array(colors))
ax.add_collection(p, autolim=True)
plt.colorbar(p)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment