Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetworkX - How to change the shape of the node?

I know that we can choose the shape from so^>v<dph8.

Is there a way to modify the shape of a node so that it contains the name of the node ?

I'm interested by custom shapes (or that can have a size that adapts to the text it contains).

like image 595
DavidK Avatar asked May 20 '15 08:05

DavidK


People also ask

Does NetworkX use GPU?

RAPIDS's graph algorithms like PageRank and functions like NetworkX make efficient use of the massive parallelism of GPUs to accelerate analysis of large graphs by over 1000X.

Can NetworkX handle large graphs?

For NetworkX, a graph with more than 100K nodes may be too large. I'll demonstrate that it can handle a network with 187K nodes in this post, but the centrality calculations were prolonged. Luckily, there are some other packages available to help us with even larger graphs.


2 Answers

I can suggest to have a bbox around the label instead of changing shape of the node. In this case node will "contain the name" inside the box and to acheive this you need specify bbox parameters as dictionary

nx.draw(G, pos=pos, with_labels=True,  node_shape="s",  node_color="none", bbox=dict(facecolor="skyblue", edgecolor='black', boxstyle='round,pad=0.2'))

You may also consider this solution here

like image 65
Yury Wallet Avatar answered Sep 18 '22 09:09

Yury Wallet


You can draw nodes and their labels with the following code:

nx.draw_networkx_nodes(G, pos, node_size=600, node_color='w', alpha=0.4, node_shape='d')
nx.draw_networkx_labels(G, pos, font_size=20, font_family='sans-serif')

For a complete example you can look at the code of the networkx gallery here.

Edit: To fit the name inside the node, you have to play with the node size and font size.

Proof:

example

like image 24
Kirell Avatar answered Sep 22 '22 09:09

Kirell