diff options
Diffstat (limited to 'ero1/src/helper/color_suburbs.py')
| -rw-r--r-- | ero1/src/helper/color_suburbs.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/ero1/src/helper/color_suburbs.py b/ero1/src/helper/color_suburbs.py new file mode 100644 index 0000000..7668999 --- /dev/null +++ b/ero1/src/helper/color_suburbs.py @@ -0,0 +1,70 @@ +import osmnx as ox + +colors = [ + "#e6194b", # rouge vif 1 + "#3cb44b", # vert vif 2 + "#ffe119", # jaune 3 + "#4363d8", # bleu 4 + "#f58231", # orange 5 + "#911eb4", # violet 6 + "#46f0f0", # cyan clair 7 + "#f032e6", # rose 8 + "#bcf60c", # vert citron 9 + "#fabebe", # rose pâle 10 + "#008080", # turquoise foncé 11 + "#e6beff", # lavande 12 + "#9a6324", # brun 13 + "#fffac8", # crème 14 + "#800000", # bordeaux 15 + "#aaffc3", # vert menthe 16 + "#808000", # olive 17 + "#ffd8b1", # pêche 18 + "#000075", # bleu marine 19 +] + + +def display_suburbs_with_colors(G, path, connections=None): + """ + Colorie chaque quartier d'une couleur différente + Parameter: + path (map<String, List<(int, int, data)>>: resultat du postier chinois, + G (DiGraph): graph de montreal + Result: + void + """ + + associated_color = {} + connection_color = "#FFFFFF" # noir + + i = 0 + for suburb in path: + for u, v in path[suburb]: + if (v,u) in G.edges(keys=False): + associated_color[(v, u)] = colors[i] + associated_color[(u, v)] = colors[i] + + i += 1 + + if connections: + for _, _, conn_path in connections: + if conn_path is None or len(conn_path) < 2: + continue + for i in range(len(conn_path) - 1): + u, v = conn_path[i], conn_path[i + 1] + if (v, u) in G.edges(keys=False): + associated_color[(v, u)] = connection_color + associated_color[(u, v)] = connection_color + + count = 0 + edge_colors = [] + for u, v in G.edges(keys=False): + if (u,v) in associated_color: + edge_colors.append(associated_color[(u, v)]) + count += 1 + else: + edge_colors.append("grey") + + # print(f"{count} arêtes colorées (quartiers + connexions)") + + fig, ax = ox.plot_graph(G, edge_color=edge_colors, + node_size=0, edge_linewidth=1) |
