簡體   English   中英

點熊貓之間的繪圖線

[英]plot line between points pandas

我想在兩點之間繪制線,並且我的點在不同的列中定義。

#coordinates of the points
#point1(A[0],B[0])
#point2(C[0],D[0])
#line between point1 and point 2

#next line would be
#point3(A[1],B[1])
#point4(C[1],D[1])    
#line between point3 and point 4

plot_result:
   A  B  C  D  E  F
0  0  4  7  1  5  1
1  2  5  8  3  3  1
2  3  4  9  5  6  1
3  4  5  4  7  9  4
4  6  5  2  1  2  7
5  1  4  3  0  4  7

我嘗試使用此代碼:

import numpy as np
import matplotlib.pyplot as plt
for i in range(0, len(plot_result.A), 1):
    plt.plot(plot_result.A[i]:plot_result.B[i], plot_result.C[i]:plot_result.D[i], 'ro-')

plt.show()

但這是無效的語法。 我不知道如何實現

方法圖的前兩個參數是x和y,它們可以是單點或類似數組的對象。 如果要繪制從點(x1,y1)到點(x2,y2)的線,則必須執行以下操作:

for plot_result in plot_result.values: # if plot_results is a DataFrame
    x1 = row[0] # A[i]
    y1 = row[1] # B[i]
    x2 = row[2] # C[i]
    y2 = row[3] # D[i]
    plt.plot([x1,x2],[y1,y2]) # plot one line for every row in the DataFrame.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM