draw_networkx(G, pos=None, arrows=None, with_labels=True, **kwds)
Draw the graph with Matplotlib with options for node positions, labeling, titles, and many other drawing features. See draw() for simple drawing without labels or axes.
For directed graphs, arrows are drawn at the head end. Arrows can be turned off with keyword arrows=False.
A networkx graph
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.
If :None:None:`None`
, directed graphs draw arrowheads with FancyArrowPatch
, while undirected graphs draw edges via LineCollection
for speed. If :None:None:`True`
, draw arrowheads with FancyArrowPatches (bendable and stylish). If :None:None:`False`
, draw edges using LineCollection (linear and fast). For directed graphs, if True draw arrowheads. Note: Arrows will be the same color as edges.
For directed graphs, choose the style of the arrowsheads. For undirected graphs default to '-'
See matplotlib.patches.ArrowStyle
for more options.
For directed graphs, choose the size of the arrow head's length and width. A list of values can be passed in to assign a different size for arrow head's length and width. See matplotlib.patches.FancyArrowPatch
for attribute :None:None:`mutation_scale`
for more info.
Set to True to draw labels on the nodes.
Draw the graph in the specified Matplotlib axes.
Draw only specified nodes
Draw only specified edges
Size of nodes. If an array is specified it must be the same length as nodelist.
Node color. Can be a single color or a sequence of colors with the same length as nodelist. Color can be string or rgb (or rgba) tuple of floats from 0-1. If numeric values are specified they will be mapped to colors using the cmap and vmin,vmax parameters. See matplotlib.scatter for more details.
The shape of the node. Specification is as matplotlib.scatter marker, one of 'so^>v<dph8'.
The node and edge transparency
Colormap for mapping intensities of nodes
Minimum and maximum for node colormap scaling
Line width of symbol border
Line width of edges
Edge color. Can be a single color or a sequence of colors with the same length as edgelist. Color can be string or rgb (or rgba) tuple of floats from 0-1. If numeric values are specified they will be mapped to colors using the edge_cmap and edge_vmin,edge_vmax parameters.
Colormap for mapping intensities of edges
Minimum and maximum for edge colormap scaling
Edge line style e.g.: '-', '--', '-.', ':' or words like 'solid' or 'dashed'. (See matplotlib.patches.FancyArrowPatch
: :None:None:`linestyle`
)
Node labels in a dictionary of text labels keyed by node
Font size for text labels
Font color string
Font weight
Font family
Label for graph legend
See networkx.draw_networkx_nodes(), networkx.draw_networkx_edges(), and networkx.draw_networkx_labels() for a description of optional keywords.
Draw the graph G using Matplotlib.
>>> G = nx.dodecahedral_graph()
... nx.draw(G)
... nx.draw(G, pos=nx.spring_layout(G)) # use spring layout
>>> import matplotlib.pyplot as plt
... limits = plt.axis("off") # turn off axis
Also see the NetworkX drawing examples at https://networkx.org/documentation/latest/auto_examples/index.html
See :The following pages refer to to this document either explicitly or contain code examples using this.
networkx.drawing.nx_pylab.draw_circular
networkx.drawing.nx_pylab.draw_shell
networkx.drawing.nx_pylab.draw
networkx.drawing.nx_pylab.draw_kamada_kawai
networkx.drawing.nx_pylab.draw_networkx_labels
networkx.drawing.nx_pylab.draw_networkx_edge_labels
networkx.drawing.nx_pylab.draw_networkx_edges
networkx.drawing.nx_pylab.draw_spring
networkx.drawing.nx_pylab.draw_random
networkx.drawing.nx_pylab.draw_spectral
networkx.drawing.nx_pylab.draw_networkx_nodes
networkx.drawing.nx_pylab.draw_planar
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them