地図を描くスタンダードな方法
mpl_toolkits.basemapというのが、スタンダード。
しかし、pyplotで何とか地図を描けないだろうか。
このサイトから地図データがダウンロードできる。
国土数値情報ダウンロードサービスで、
“N03-110331_28_EC01.shp”というのを、ダウンロードしてみた。
shapeファイルをプロットしてみた
これでできた。変数eは変換行列になっているので、いろいろ試すといいかもしれない。
必要なファイル。
カレントフォルダに、”N03-110331_28_EC01.shp”
windows 日本語使用のコード
#!/usr/bin/env python
# -*- coding: cp932 -*-
import time
from datetime import datetime as dt
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = 'IPAGothic'
import shapefile
#下の文字列に、シェイプファイルのアドレスを入力する。
sf = shapefile.Reader(r"N03-110331_28_EC01.shp",encoding='SHIFT-JIS') #,encoding='SHIFT-JIS'必須
f,(ax1) = plt.subplots(1,1)
e = [[1, 0], [0, 1]]#変換行列
a = 133.5
try:
i = 0
while True:
shape = sf.shape(i)
x = []
y = []
x2 = []
y2 = []
for i2 in range(len(shape.points)):
x.append(shape.points[i2][0])
y.append(shape.points[i2][1])
b = shape.points[i2]
c = [a, 0]
d = [b[0] - c[0], b[1] - c[1]]
#e = [[1, 0], [0, 1]]
f2 = np.dot(d, e)
c2 = [a, 0]
f2 = [f2[0] + c2[0], f2[1] + c2[1]]
x2.append(f2[0])
y2.append(f2[1])
#ax1.plot(x, y, color="k")
ax1.plot(x, y, color="k", linestyle="--")
ax1.plot(x2, y2, color="k", clip_on=False)
i += 1
except IndexError or UnicodeDecodeError or TypeError:
pass
ax1.set_aspect('equal')
ax1.grid(which="major", color="black", linestyle="--")
ax1.plot([a,a], [25,40], color="k", linestyle="dashdot" ,clip_on=False)
ax1.set_xlim(130, 137)
ax1.set_ylim(30, 37)
ax1.set_title(ur"兵庫県の地図")
ax1.set_xlabel(ur"経度(度)")
ax1.set_ylabel(ur"緯度(度)")
#plt.show()
tdatetime = dt.now()
itext = tdatetime.strftime('%Y%m%d'+ time.ctime()[11:13] + time.ctime()[14:16] + time.ctime()[17:19])
f.set_size_inches(19.2,10.8)
f.savefig("%s.png"%(itext))
【pythonの最新記事】
- 中速フーリエ変換 ~離散フーリエ変換より..
- 断面二次モーメントを、座標点の配列から計..
- 断面二次モーメントを、座標点の配列から計..
- fontファイルの文字データ(グリフ)を..
- 計算力学技術者試験の問題集 自炊(裁断→..
- pythonで、ホワイトノイズやピンクノ..
- 脳ドッグに行ってきた。→MRIの画像デー..
- matplotlibのimshowで円を..
- matplotlibの、cmapを、徐々..
- matplotlibのmake_axes..
- matplotlib floatinga..
- matplotlib plotの色を、値..
- Pythonで、「二次元フーリエ変換した..
- matplotlibのlinestyle..
- どちらが正しいRGBか。(matplot..
- matplotlibのannotateの..
- matplotlibで、x軸とy軸の数字..
- VBAで、pythonのrangeとか、..
- matplotlibのaxes3Dで、a..
- matplotlibのlatexで、行列..