From 15df99510f358b45cde0a6e0376eaa78f30f380c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= Date: Sat, 1 Aug 2020 22:55:01 +0200 Subject: [PATCH] plot: Show something useful for missing city names This makes it possible to render at least something on tiny topologies now that YANG doesn't support city labels. Change-Id: I1431b557b2eecd34bf24557fdee0da0f2c2c0487 --- gnpy/tools/plots.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gnpy/tools/plots.py b/gnpy/tools/plots.py index e74a6b9c..a169dc78 100755 --- a/gnpy/tools/plots.py +++ b/gnpy/tools/plots.py @@ -13,10 +13,14 @@ from networkx import draw_networkx_nodes, draw_networkx_edges, draw_networkx_lab from gnpy.core.elements import Transceiver +def _try_city(node): + return node.location.city if node.location.city else node.uid + + def plot_baseline(network): edges = set(network.edges()) pos = {n: (n.lng, n.lat) for n in network.nodes()} - labels = {n: n.location.city for n in network.nodes() if isinstance(n, Transceiver)} + labels = {n: _try_city(n) for n in network.nodes() if isinstance(n, Transceiver)} city_labels = set(labels.values()) for n in network.nodes(): if n.location.city and n.location.city not in city_labels: @@ -40,7 +44,8 @@ def plot_results(network, path, source, destination): nodes = {} for k, (x, y) in pos.items(): nodes.setdefault((round(x, 1), round(y, 1)), []).append(k) - labels = {n: n.location.city for n in network.nodes() if isinstance(n, Transceiver)} + + labels = {n: _try_city(n) for n in network.nodes() if isinstance(n, Transceiver)} city_labels = set(labels.values()) for n in network.nodes(): if n.location.city and n.location.city not in city_labels: @@ -56,7 +61,7 @@ def plot_results(network, path, source, destination): draw_networkx_edges(network, edgelist=edges, edge_color='#ababab', **kwargs) draw_networkx_edges(network, edgelist=path_edges, edge_color='#ff0000', **kwargs) draw_networkx_labels(network, labels=labels, font_size=14, **{**kwargs, 'pos': label_pos}) - title(f'Propagating from {source.loc.city} to {destination.loc.city}') + title(f'Propagating from {_try_city(source)} to {_try_city(destination)}') axis('off') heading = 'Spectral Information\n\n'