networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersBackRef
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.

Notes

For directed graphs, arrows are drawn at the head end. Arrows can be turned off with keyword arrows=False.

Parameters

G : graph

A networkx graph

pos : dictionary, 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.

arrows : bool or None, optional (default=None)

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.

arrowstyle : str (default='-\|>' for directed graphs)

For directed graphs, choose the style of the arrowsheads. For undirected graphs default to '-'

See matplotlib.patches.ArrowStyle for more options.

arrowsize : int or list (default=10)

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.

with_labels : bool (default=True)

Set to True to draw labels on the nodes.

ax : Matplotlib Axes object, optional

Draw the graph in the specified Matplotlib axes.

nodelist : list (default=list(G))

Draw only specified nodes

edgelist : list (default=list(G.edges()))

Draw only specified edges

node_size : scalar or array (default=300)

Size of nodes. If an array is specified it must be the same length as nodelist.

node_color : color or array of colors (default='#1f78b4')

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.

node_shape : string (default='o')

The shape of the node. Specification is as matplotlib.scatter marker, one of 'so^>v<dph8'.

alpha : float or None (default=None)

The node and edge transparency

cmap : Matplotlib colormap, optional

Colormap for mapping intensities of nodes

vmin,vmax : float, optional

Minimum and maximum for node colormap scaling

linewidths : scalar or sequence (default=1.0)

Line width of symbol border

width : float or array of floats (default=1.0)

Line width of edges

edge_color : color or array of colors (default='k')

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.

edge_cmap : Matplotlib colormap, optional

Colormap for mapping intensities of edges

edge_vmin,edge_vmax : floats, optional

Minimum and maximum for edge colormap scaling

style : string (default=solid line)

Edge line style e.g.: '-', '--', '-.', ':' or words like 'solid' or 'dashed'. (See matplotlib.patches.FancyArrowPatch : :None:None:`linestyle`)

labels : dictionary (default=None)

Node labels in a dictionary of text labels keyed by node

font_size : int (default=12 for nodes, 10 for edges)

Font size for text labels

font_color : string (default='k' black)

Font color string

font_weight : string (default='normal')

Font weight

font_family : string (default='sans-serif')

Font family

label : string, optional

Label for graph legend

kwds : optional keywords

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.

See Also

draw
draw_networkx_edge_labels
draw_networkx_edges
draw_networkx_labels
draw_networkx_nodes

Examples

>>> 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 :

Back References

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

Local connectivity graph

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


GitHub : /networkx/drawing/nx_pylab.py#126
type: <class 'function'>
Commit: