def make_segments ( x , y ) : points = np . array ( [ x , y ] ) . T . reshape ( - 1 , 1 , 2 ) segments = np . concatenate ( [ points [ : - 1 ] , points [ 1 : ] ] , axis = 1 ) return segments
python construct parallel line segments
Create list of line segments from x and y coordinates in the correct format for LineCollection : an array of the form numlines x ( points per line ) x 2 ( x and y ) array
def make_segments(x, y):
    """
    Create list of line segments from x and y coordinates, in the correct format
    for LineCollection: an array of the form numlines x (points per line) x 2 (x
    and y) array
    """

    points = np.array([x, y]).T.reshape(-1, 1, 2)
    segments = np.concatenate([points[:-1], points[1:]], axis=1)
    return segments