From b85a2275238720ca32ea4277688f0eef107c51be Mon Sep 17 00:00:00 2001 From: Niko Savola Date: Mon, 17 Jun 2024 13:53:17 +0300 Subject: [PATCH] Color net labels differently in imported SPICE graph --- gplugins/klayout/netlist_graph.py | 4 ++++ gplugins/klayout/plot_nets.py | 14 ++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/gplugins/klayout/netlist_graph.py b/gplugins/klayout/netlist_graph.py index ed27d7b7..93242f58 100644 --- a/gplugins/klayout/netlist_graph.py +++ b/gplugins/klayout/netlist_graph.py @@ -91,6 +91,10 @@ def netlist_to_networkx( G.add_edge(device_name, net_name) all_used_nets.add(net_name) + # Easier to set different colors for nets + for net in all_used_nets: + G.nodes[net]["is_net"] = True + if not include_labels: for node in all_used_nets: connections = list(G.neighbors(node)) diff --git a/gplugins/klayout/plot_nets.py b/gplugins/klayout/plot_nets.py index ef622bfd..af126afe 100644 --- a/gplugins/klayout/plot_nets.py +++ b/gplugins/klayout/plot_nets.py @@ -76,16 +76,22 @@ def _removal_condition(node: str, degree: int) -> bool: net.from_nx(G_connectivity) net.show("connectivity.html") else: - plt.figure(figsize=(8, 6)) + color_nets = [ + "lightblue" + if G_connectivity.nodes[node].get("is_net", False) + else "lightpink" + for node in G_connectivity.nodes() + ] + + fig = plt.figure(figsize=(8, 6)) nx.draw( G_connectivity, with_labels=True, node_size=2000, - node_color="lightpink", + node_color=color_nets, font_size=12, ) - plt.title("Connectivity") - return plt + return fig if __name__ == "__main__":