绘制图形的最短路径

时间:2019-05-02 09:05:37

标签: python

我有一组坐标,想找到从最接近x = 0,y = 0的坐标到距离它最远的坐标的最短路径,并将其显示在图形上。反正我能做到吗?

以下是感兴趣的坐标:

TaskSchedulerImpl:66 - Initial job has not accepted any resources; check your cluster UI to ensure that workers are registered and have sufficient resources 

除此之外,是否也可以找到图的直径(从a到b)?

1 个答案:

答案 0 :(得分:0)

这应该使您入门。我还没有做任何漂亮的事情,但是基础知识就在那里 供您继续使用。

import matplotlib.pyplot as plt
import numpy as np

xy = np.array([[23, 292], [78, 275], [187, 81], [188, 430], [198, 150], [204, 180],         
              [222, 245], [223, 175], [226, 334], [255, 344], [263, 213], [266, 261], 
              [286, 163], [301, 266], [328, 206], [352, 42], [363, 169], [379, 177], 
              [385, 187], [394, 211], [400, 254], [401, 199], [412, 335], [420, 371],
              [434, 176], [449, 174], [457, 230], [472, 136]])
lengths = np.linalg.norm(xy, axis=1)
minindex = np.argmin(lengths)
maxindex = np.argmax(lengths)
diameter = lengths[maxindex] - lengths[minindex]
linex = (xy[minindex, 0], xy[maxindex, 0])
liney = (xy[minindex, 1], xy[maxindex, 1])
plt.scatter(xy[:, 0], xy[:, 1])
plt.plot(linex, liney)
plt.show()

不确定您的diameter问题,但我有个主意。