geo-matplot.py 949 Bytes
# 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()