-
Notifications
You must be signed in to change notification settings - Fork 3
/
cities_graph.py
50 lines (44 loc) · 1.13 KB
/
cities_graph.py
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
"""
Author: Sonu Prasad
Email: sonu.prasad@mycit.ie
file: cities_graph.py
"""
import plotly as py
import numpy as np
def plot_graph(cities, length_of_route, file_name):
"""
Generates TSP Graph using Plotly
:param cities: list of cities
:param length_of_route: Total cost of cities
:param file_name: For saving the graph
:return: void
"""
cities_arr = np.array(cities)
cities_arr = np.vstack([cities_arr, cities_arr[0]])
trace0 = {
"x": cities_arr[:, 0],
"y": cities_arr[:, 1],
"name": 'col2',
"type": 'scatter',
"mode": 'lines+markers'
}
data = [trace0]
layout = {
"autosize": True,
"font": {"color": "rgb(61, 133, 198)"},
"showlegend": True,
"title": "Length of the route is {}".format(length_of_route),
"titlefont": {"color": "rgb(153, 0, 255)"},
"xaxis": {
"autorange": True,
"title": "",
"type": "linear"
},
"yaxis": {
"autorange": True,
"title": "",
"type": "linear"
}
}
fig = dict(data=data, layout=layout)
py.offline.plot(fig, filename=file_name)