我的df表中有四個坐標:
| lat1 | lon1 | lat2 | lon2 | lat3 | lon3 | lat4lon4 |
|---|---|---|---|---|---|---|
| 51.071833 | ||||||
| 6.237204 | 6.237204
基于這些資料,我試圖將這些點以這樣的方式連接起來,從而形成一個平行四邊形。
散點圖:
# selecting columns start with 'lat'
xx = df[[col for col in test if col.startswith('lat')].stack().to_list()
#選擇以'lon'開始的列。
yy = df[[col for col in test if col.startswith('lon')]] .stack().to_list()
plt.scatter(xx,yy)
不幸的是,當我試圖用線連接點時,它不起作用:
plt.scatter(xx,yy)
plt.plot(xx,yy)。
預期結果:
我想這是因為這些點沒有被排序。我還試過這樣做:
points = np.c_[xx, yy] 。
from sklearn.neighbors import NearestNeighbors
clf = NearestNeighbors(2).fit(point)
G = clf.kneighbors_graph()
import networkx as nx
T = nx.from_scipy_sparse_matrix(G)
order = list(nx.dfs_preorder_nodes(T, 0)
xx = xx[順序]
yy = yy[順序]
plt.plot(xx, yy)
plt.show()
但它仍然是不正確的。
你知道問題出在哪里嗎?
謝謝
uj5u.com熱心網友回復:
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/312398.html
標籤:
上一篇:如何繪制一個半圓的方程




