draw#

draw(G, pos=None, ax=None, **kwds)[source]#

Draw the graph G with Matplotlib.

Draw the graph as a simple representation with no node labels or edge labels and using the full Matplotlib figure area and no axis labels by default. See draw_networkx() for more full-featured drawing that allows title, axis labels etc.

Parameters:
Ggraph

A networkx graph

posdictionary, optional

A dictionary with nodes as keys and positions as values. If not specified a spring layout positioning will be computed. See networkx.drawing.layout for functions that compute node positions.

axMatplotlib Axes object, optional

Draw the graph in specified Matplotlib axes.

kwdsoptional keywords

See networkx.draw_networkx() for a description of optional keywords.

Notes

This function has the same name as pylab.draw and pyplot.draw so beware when using from networkx import *

since you might overwrite the pylab.draw function.

With pyplot use

>>> import matplotlib.pyplot as plt
>>> G = nx.dodecahedral_graph()
>>> nx.draw(G)  # networkx draw()
>>> plt.draw()  # pyplot draw()

Also see the NetworkX drawing examples at https://networkx.org/documentation/latest/auto_examples/index.html

Examples

>>> G = nx.dodecahedral_graph()
>>> nx.draw(G)
>>> nx.draw(G, pos=nx.spring_layout(G))  # use spring layout