geo-matplot.py
949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# coding=utf-8
#author: 4N
#createtime: 2022/3/14
#email: nheweijun@sina.com
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.collections import PolyCollection,LineCollection
import matplotlib as mpl
from PIL import Image
import os
def draw(geom):
rectangle = [(0, 0), (0, 1), (1, 1), (1, 0),(0, 0)]
# hexagon = [(0, 0), (0, 1), (1, 2), (2, 1), (2, 0), (1, -1)]
l_shape = [(0, 0), (0, 3), (1, 3), (1, 1), (3, 1), (3, 0)]
# concave = [(0, 0), (0, 3), (1, 3), (1, 1), (2, 1), (2, 3), (3, 3), (3, 0)]
for points in [rectangle,l_shape]:
xs, ys = zip(*points)
# plt.plot(xs, ys, 'o')
plt.plot(xs, ys, '-')
plt.axis('off')
png_path = "F:/temp.png"
plt.savefig(png_path)
png = Image.open(png_path)
tif_path = "F:/temp.tif"
png.save(tif_path)
os.remove(png_path)
if __name__ == '__main__':
draw()