Plotting lines connecting points

前端 未结 4 1751
挽巷
挽巷 2020-12-03 02:32

I know there is another very similar question, but I could not extract the information I need from it.

plotting lines in pairs

I have 4 points in the (

4条回答
  •  天涯浪人
    2020-12-03 03:33

    Use the matplotlib.arrow() function and set the parameters head_length and head_width to zero to don't get an "arrow-end". The connections between the different points can be simply calculated using vector addition with: A = [1,2], B=[3,4] --> Connection between A and B is B-A = [2,2]. Drawing this vector starting at the tip of A ends at the tip of B.

    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib import style
    style.use('fivethirtyeight')
    
    
    A = np.array([[10,8],[1,2],[7,5],[3,5],[7,6],[8,7],[9,9],[4,5],[6,5],[6,8]])
    
    
    fig = plt.figure(figsize=(10,10))
    ax0 = fig.add_subplot(212)
    
    ax0.scatter(A[:,0],A[:,1])
    
    
    ax0.arrow(A[0][0],A[0][1],A[1][0]-A[0][0],A[1][1]-A[0][1],width=0.02,color='red',head_length=0.0,head_width=0.0)
    ax0.arrow(A[2][0],A[2][1],A[9][0]-A[2][0],A[9][1]-A[2][1],width=0.02,color='red',head_length=0.0,head_width=0.0)
    ax0.arrow(A[4][0],A[4][1],A[6][0]-A[4][0],A[6][1]-A[4][1],width=0.02,color='red',head_length=0.0,head_width=0.0)
    
    
    plt.show()
    

提交回复
热议问题