Networkx Draw_Network Draws a Frame Around the Plot. How Can I Prevent This?

I do some manipulations on graphs/networks and want to plot the results and save them to a pdf (actually the format does not really matter, but I think pdf is fine).

I give you a minimal example:

import networkx as nx
from matplotlib import pyplot as plt

g=nx.erdos_renyi_graph(20,.2,directed=True)
nx.draw_networkx(g)
#plt.show()
plt.savefig('so_example.pdf', bbox_inches='tight')

The result is OK, except that there is a thick black frame around the picture:

Does anybody know a way to prevent this frame?

1 Answer

You could use plt.box(False). See code below:

import networkx as nx
from matplotlib import pyplot as plt

g=nx.erdos_renyi_graph(20,.2,directed=True)
nx.draw_networkx(g)
plt.box(False)
plt.show()

And the output gives:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest