Skip to content Skip to sidebar Skip to footer

Networkx Drawing Label Partially Outside The Box

Just draw a very simple 4-node network, import networkx as nx import matplotlib.pyplot as plt G = nx.Graph() node1 = '116.251.211.248' node2 = '5.79.100.165' node3 = 'http.anturis.

Solution 1:

Unfortunately, there does not seem to be an automated procedure for fixing the margins. You can adjust the margins by hand by calling plt.xlim(xmin,xmax). Since you know the node positions (pos), you can add, say, an extra 25% on each side:

#Your code here....
nx.draw(G, pos, with_labels=True)
x_values, y_values = zip(*pos.values())
x_max = max(x_values)
x_min = min(x_values)
x_margin = (x_max - x_min) * 0.25
plt.xlim(x_min - x_margin, x_max + x_margin)
plt.show()

enter image description here

Post a Comment for "Networkx Drawing Label Partially Outside The Box"