(vectors, sumup=True, min_max_x=None, min_max_y=None, 
                    cmap=plt.cm.viridis_r, colors=None, vector_labels=None,
                    ax=None)
return ax
Plots 2d vectors by adding them in sequence and transposing them.
    
    Parameters
    ----------
    vectors : list 
        2D vectors eg: [[0,1], [3,4]]
    sumup : bool
        Show a vector that represents a sum of vectors
    min_max_{x,y} : tuple
        min and max of {x,y} axis
    cmap : plt.cm
        Default: plt.cm.viridis_r
    colors : list
        List of matplotlib colors. Number of colors has to match number of vecors
        (including sum vector if sumup=True). Default=None selects colors from cmap
    vector_labels : list
        Has to match number of vecors (including sum vector if sumup=True)
    ax : plt.ax
        Name of axis to plot to
    Returns
    -------
    plt.figure()
Plots 2d vectors by adding them in sequence and transposing them.
    
    Parameters
    ----------
    vectors : list 
        2D vectors eg: [[0,1], [3,4]]
    sumup : bool
        Show a vector that represents a sum of vectors
    min_max_{x,y} : tuple
        min and max of {x,y} axis
    cmap : plt.cm
        Default: plt.cm.viridis_r
    colors : list
        List of matplotlib colors. Number of colors has to match number of vecors
        (including sum vector if sumup=True). Default=None selects colors from cmap
    vector_labels : list
        Has to match number of vecors (including sum vector if sumup=True)
    ax : plt.ax
        Name of axis to plot to
    Returns
    -------
    plt.figure()
Plots 2d vectors by adding them in sequence and transposing them . Parameters ---------- vectors : list 2D vectors eg : [[ 0 1 ] [ 3 4 ]] sumup : bool Show a vector that represents a sum of vectors min_max_ { x y } : tuple min and max of { x y } axis cmap : plt . cm Default : plt . cm . viridis_r colors : list List of matplotlib colors . Number of colors has to match number of vecors ( including sum vector if sumup = True ) . Default = None selects colors from cmap vector_labels : list Has to match number of vecors ( including sum vector if sumup = True ) ax : plt . ax Name of axis to plot to Returns ------- plt . figure ()
def plot_2D_vectors(vectors, sumup=True, min_max_x=None, min_max_y=None, 
                    cmap=plt.cm.viridis_r, colors=None, vector_labels=None,
                    ax=None):
    """Plots 2d vectors by adding them in sequence and transposing them.
    
    Parameters
    ----------
    vectors : list 
        2D vectors eg: [[0,1], [3,4]]
    sumup : bool
        Show a vector that represents a sum of vectors
    min_max_{x,y} : tuple
        min and max of {x,y} axis
    cmap : plt.cm
        Default: plt.cm.viridis_r
    colors : list
        List of matplotlib colors. Number of colors has to match number of vecors
        (including sum vector if sumup=True). Default=None selects colors from cmap
    vector_labels : list
        Has to match number of vecors (including sum vector if sumup=True)
    ax : plt.ax
        Name of axis to plot to
    Returns
    -------
    plt.figure()
    """
    # Transform the vectors
    soa = []  # vectors with x,y of start point and x,y of end point
    for x in vectors:
        if len(soa) == 0:
            soa.append([0, 0]+list(x))
        else:
            last = soa[-1]
            soa.append([last[0]+last[2]]+[last[1]+last[3]]+list(x))
    if sumup:
        soa.append([0, 0]+list(sum(vectors)))
    X, Y, U, V = zip(*soa)
    if not ax:
        f = plt.figure()
        ax = plt.gca()
    if not colors and sumup:
        colors = [[cmap.colors[120]]*(len(soa)-1)][0] + [cmap.colors[-1]]
    if not colors and not sumup:
        colors = [[cmap.colors[120]]*(len(soa))][0]
    if vector_labels:
        if (len(vector_labels) != len(vectors)) and sumup is False:
            raise Exception('Number of vectors does not match the number of labels')
        if (len(vector_labels) != len(vectors) + 1) and sumup is True:
            raise Exception('Number of vectors does not match the number of labels')
        for x, y, u, v, c, vl in zip(X, Y, U, V, colors, vector_labels):
            Q = ax.quiver(x, y, u, v, color=c, angles='xy', scale_units='xy', scale=1)
            ax.quiverkey(Q, x, y, u, vl, coordinates='data', color=[0, 0, 0, 0], labelpos='N')
    else:
        ax.quiver(X, Y, U, V, color=colors, angles='xy', scale_units='xy', scale=1)
    # set plot limits based on positions of vectors
    if not min_max_x:
        min_max_x = min([x[0] + x[2] for x in soa]), max([x[0] for x in soa])
    if not min_max_y:
        min_max_y = min([x[1] + x[3] for x in soa]), max([x[1] for x in soa])
    # margins on each side
    margin_x, margin_y = sum(min_max_x)/10., sum(min_max_y)/10.
    ax.set_xlim(min_max_x[0]+margin_x, min_max_x[1]-margin_x)
    ax.set_ylim(min_max_y[0]-margin_y, min_max_y[1]+margin_y)
    return ax
def plot_2D_vectors ( vectors , sumup = True , min_max_x = None , min_max_y = None , cmap = plt . cm . viridis_r , colors = None , vector_labels = None , ax = None ) : # Transform the vectors soa = [ ] # vectors with x,y of start point and x,y of end point for x in vectors : if len ( soa ) == 0 : soa . append ( [ 0 , 0 ] + list ( x ) ) else : last = soa [ - 1 ] soa . append ( [ last [ 0 ] + last [ 2 ] ] + [ last [ 1 ] + last [ 3 ] ] + list ( x ) ) if sumup : soa . append ( [ 0 , 0 ] + list ( sum ( vectors ) ) ) X , Y , U , V = zip ( * soa ) if not ax : f = plt . figure ( ) ax = plt . gca ( ) if not colors and sumup : colors = [ [ cmap . colors [ 120 ] ] * ( len ( soa ) - 1 ) ] [ 0 ] + [ cmap . colors [ - 1 ] ] if not colors and not sumup : colors = [ [ cmap . colors [ 120 ] ] * ( len ( soa ) ) ] [ 0 ] if vector_labels : if ( len ( vector_labels ) != len ( vectors ) ) and sumup is False : raise Exception ( 'Number of vectors does not match the number of labels' ) if ( len ( vector_labels ) != len ( vectors ) + 1 ) and sumup is True : raise Exception ( 'Number of vectors does not match the number of labels' ) for x , y , u , v , c , vl in zip ( X , Y , U , V , colors , vector_labels ) : Q = ax . quiver ( x , y , u , v , color = c , angles = 'xy' , scale_units = 'xy' , scale = 1 ) ax . quiverkey ( Q , x , y , u , vl , coordinates = 'data' , color = [ 0 , 0 , 0 , 0 ] , labelpos = 'N' ) else : ax . quiver ( X , Y , U , V , color = colors , angles = 'xy' , scale_units = 'xy' , scale = 1 ) # set plot limits based on positions of vectors if not min_max_x : min_max_x = min ( [ x [ 0 ] + x [ 2 ] for x in soa ] ) , max ( [ x [ 0 ] for x in soa ] ) if not min_max_y : min_max_y = min ( [ x [ 1 ] + x [ 3 ] for x in soa ] ) , max ( [ x [ 1 ] for x in soa ] ) # margins on each side margin_x , margin_y = sum ( min_max_x ) / 10. , sum ( min_max_y ) / 10. ax . set_xlim ( min_max_x [ 0 ] + margin_x , min_max_x [ 1 ] - margin_x ) ax . set_ylim ( min_max_y [ 0 ] - margin_y , min_max_y [ 1 ] + margin_y ) return ax