Demo entry 6658768

show

   

Submitted by anonymous on Nov 08, 2017 at 12:14
Language: Python 3. Code size: 720 Bytes.

import operator
import matplotlib.pyplot as plt


def plot(points, path: list):
    x = []
    y = []
    for point in points:
        x.append(point[0])
        y.append(point[1])
    
    y = list(map(operator.sub, [max(y) for i in range(len(points))], y))
    plt.plot(x, y, 'co')

    for _ in range(1, len(path)):
        i = path[_ - 1]
        j = path[_]
        
        plt.arrow(x[i], y[i], x[j] - x[i], y[j] - y[i], color='r', length_includes_head=True)

    (start, end) = (path[0], path[-1]) #首位相连
    plt.arrow(x[end], y[end], x[start] - x[end], y[start] - y[end], color='r', length_includes_head=True)
    plt.xlim(0, max(x) * 1.1)
    plt.ylim(0, max(y) * 1.1)
    plt.show() #绘图

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).