'is there a way in Python to plot an aesthetically decent networkx graph with self-loops?

I generated a network using networkx package:

import pandas as pd
import numpy as np
import networkx as nx
import nxviz
from matplotlib import pyplot as plt



n_nodes = 6

#define a complete graph
G = nx.complete_graph(n_nodes)

#add the self-loops
G.add_edges_from([(i,i) for i in range(n_nodes)])

#add some random size and color for nodes
nx.set_node_attributes(G, {node:np.random.random() for node in G.nodes}, name="size")
nx.set_node_attributes(G, {node:"#%03x" % np.random.randint(0, 0xFFFFFF) for node in G.nodes}, name="color")

#add some random intensity for edges
nx.set_edge_attributes(G, {(i,j):np.random.randint(0,10) for i in range(n_nodes) for j in range(i+1)}, name="intensity")

I have used nxviz package to plot G in this way:

plt.figure(figsize=(10,10))
nxviz.arc(G, node_color_by="color", node_size_by="size", edge_lw_by="intensity", )
plt.show()

my output plot

This is a very nice representation of my graph, except that the self-loops have not been plotted.

My question is: is there a way to obtain a similar plot with self-loops too? Recommendations regarding other tools are also accepted.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source