-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot.py
More file actions
87 lines (77 loc) · 2.41 KB
/
plot.py
File metadata and controls
87 lines (77 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import matplotlib.pyplot as plt
# Order data
orders = [
{
"ORDER_ID": "ORD002",
"pickup_coordinates": [7.2347, 10.7418],
"delivery_coordinates": [6.7634, 12.4487]
},
{
"ORDER_ID": "ORD004",
"pickup_coordinates": [7.2347, 10.7418],
"delivery_coordinates": [7.7491, 9.5289]
},
{
"ORDER_ID": "ORD001",
"pickup_coordinates": [7.2347, 10.7418],
"delivery_coordinates": [2.6792, 9.5842]
},
{
"ORDER_ID": "ORD002",
"pickup_coordinates": [7.2347, 10.7418],
"delivery_coordinates": [12.6946, 9.0711]
},
{
"ORDER_ID": "ORD003",
"pickup_coordinates": [7.2347, 10.7418],
"delivery_coordinates": [14.3056, 9.7244]
},
{
"ORDER_ID": "ORD003",
"pickup_coordinates": [7.2347, 10.7418],
"delivery_coordinates": [11.144, 6.5248]
},
{
"ORDER_ID": "ORD005",
"pickup_coordinates": [7.2347, 10.7418],
"delivery_coordinates": [12.5127, 5.157]
}
]
# Separate pickup and delivery coordinates
pickup_coords = [order["pickup_coordinates"] for order in orders]
delivery_coords = [order["delivery_coordinates"] for order in orders]
# Route data (example)
route = [
[5.7881, 13.3155],
[7.2347, 10.7418],
[7.7491, 9.5289],
[12.6946, 9.0711],
[14.3056, 9.7244],
[12.5127, 5.157],
[11.144, 6.5248],
[2.6792, 9.5842],
[6.7634, 12.4487],
[5.7881, 13.3155]
]
# Separate route into latitude and longitude
route_lats, route_longs = zip(*route)
# Plotting
plt.figure(figsize=(12, 8))
# Plot route
plt.plot(route_lats, route_longs, marker='o', linestyle='-', color='b', label="Route Path")
# Plot pickup and delivery locations
for i, order in enumerate(orders):
pickup_lat, pickup_long = order["pickup_coordinates"]
delivery_lat, delivery_long = order["delivery_coordinates"]
# Plot pickup location
plt.plot(pickup_lat, pickup_long, marker='^', color='green', markersize=10)
plt.text(pickup_lat, pickup_long, f'P{i+1}', fontsize=12, ha='right', color='green')
# Plot delivery location
plt.plot(delivery_lat, delivery_long, marker='s', color='red', markersize=10)
plt.text(delivery_lat, delivery_long, f'D{i+1}', fontsize=12, ha='right', color='red')
plt.title("Delivery Routes with Pickup and Delivery Locations")
plt.xlabel("Latitude")
plt.ylabel("Longitude")
plt.grid(True)
plt.legend()
plt.show()