Issue
I would like to draw geometric graphs that have colored nodes that can additionally have colored rings around each node.
If possible I would even like to make the surrounding color rings optional for each node.
How is it possible to (optionally) add a colored ring around different nodes in a graph?
To draw RGGs I rely on this with small modifications. There you can also add colors to the node itself. The implementation uses matplotlib to do the task.
Solution
I have a simple workaround for this:
Draw the nodes twice and then manipulate the zorder of the PathCollection such that the smaller nodes are in front:
import matplotlib.pyplot as plt
import networkx as nx
G = nx.gnp_random_graph(10, 0.5)
pos = nx.spring_layout(G)
plt.figure(figsize=(8, 8))
node_size = 50
ring_size = 100 + node_size
edges = nx.draw_networkx_edges(G, pos, alpha=0.4)
nodes = nx.draw_networkx_nodes(
G,
pos,
node_size=node_size,
node_color='red',
)
rings = nx.draw_networkx_nodes(
G,
pos,
node_size=ring_size,
node_color='green',
)
nodes.set_zorder(2)
rings.set_zorder(1)
plt.axis("off")
plt.show()
Caveat, if you want to change the alpha value of the nodes this does not work very well.
Answered By - math_noob
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.