0

我正在尝试将我的数据绘制成路径图。我试图为 4 辆汽车创建一条随机路径,而这 4 辆汽车想要拜访 5 位客户。

    #supplier_number = car _number
    customer_number=5
    supplier_number=4
    def new_xy_point():
        # data to be resides in 1st quadrant 0,90
        return uniform(0,90), uniform(0, 90)
def get_locations_as_xy(customer_number,supplier_number):
    array_xy = []
    for i in range(supplier_number):
        row =[]
        points = (new_xy_point() for x in range(customer_number)) 
        for point in points:
            row.append(point)
        array_xy.append(row)
    return array_xy

输出是:

[[(79.8124249272261, 44.151314843376966),
  (49.58192180840642, 30.506482732663542),
  (70.28912677528703, 6.087441061797694),
  (89.72384322616452, 9.047722517152833),
  (27.28544284379016, 80.71213796853516)],
 [(66.13756351247677, 23.709450654837315),
  (35.80512730273459, 0.6473958875768127),
  (4.12310992239377, 8.115202500984706),
  (9.07346347106888, 5.2704030998187665),
  (33.055743597036425, 46.21644665009771)],
 [(78.3715863238612, 25.13391992214651),
  (35.348720737093714, 46.79846937389697),
  (0.38478865512179605, 10.88617671535756),
  (80.24554838153814, 50.51948471537834),
  (60.38633980419526, 30.12729562579119)],
 [(70.16475539031165, 67.44148335547648),
  (26.47817748165972, 2.181339809429085),
  (24.303755071847856, 27.091607591419606),
  (35.889393671532545, 11.733938313695619),
  (26.76256015621871, 55.21515150952254)]]

在这里,我为每个客户设置了 x 轴和 y 轴。我需要根据这些值绘制图表。我需要输出类似i.stack.imgur.com/FH7bE.png 我对 python 和绘制 g 的经验不足,因此不胜感激。

4

1 回答 1

1

您可以使用 matplotlib 轻松绘制数据。

首先将您的数据转换为 ax 和 y 列表。在这里,我将您的数据点列表称为 a。每辆车一条路径,由相应的数字标记。

import matplotlib.pyplot as plt

for idx, row in enumerate(a):
    x, y = [], []
    for x_, y_ in row:
        x.append(x_)
        y.append(y_)
     plt.plot(x, y, label=idx)

plt.legend()
plt.show()    

在您提供的数据中,您有很多重复项,总共有 5 分。

于 2020-07-15T12:08:58.807 回答