networkx.drawing.nx_pylab.draw_networkx¶
-
draw_networkx(G, pos=None, arrows=True, with_labels=True, **kwds)[source]¶ Draw the graph G using Matplotlib.
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.
- Parameters
G (
graph) – A networkx graphpos (
dictionary, optional) – A dictionary with nodes as keys and positions as values. If not specified a spring layout positioning will be computed. Seenetworkx.drawing.layoutfor functions that compute node positions.arrows (
bool,optional (default=True)) – For directed graphs, if True draw arrowheads. Note: Arrows will be the same color as edges.arrowstyle (
str,optional (default=``’-|>’``)) – For directed graphs, choose the style of the arrowsheads. See :py:class:matplotlib.patches.ArrowStylefor more options.arrowsize (
int,optional (default=10)) – For directed graphs, choose the size of the arrow head head’s length and width. See :py:class:matplotlib.patches.FancyArrowPatchfor attributemutation_scalefor more info.with_labels (
bool,optional (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,optional (default G.nodes())) – Draw only specified nodesedgelist (
list,optional (default=G.edges())) – Draw only specified edgesnode_size (
scalarorarray,optional (default=300)) – Size of nodes. If an array is specified it must be the same length as nodelist.node_color (
colororarrayofcolors (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,optional (default=``’o’``)) – The shape of the node. Specification is as matplotlib.scatter marker, one of ‘so^>v<dph8’.alpha (
float,optional (default=None)) – The node and edge transparencycmap (
Matplotlib colormap,optional (default=None)) – Colormap for mapping intensities of nodesvmin,vmax (
float,optional (default=None)) – Minimum and maximum for node colormap scalinglinewidths (
[None | scalar | sequence]) – Line width of symbol border (default =1.0)width (
float,optional (default=1.0)) – Line width of edgesedge_color (
colororarrayofcolors (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 (default=None)) – Colormap for mapping intensities of edgesedge_vmin,edge_vmax (
floats,optional (default=None)) – Minimum and maximum for edge colormap scalingstyle (
string,optional (default=``’solid’``)) – Edge line style (solid|dashed|dotted,dashdot)labels (
dictionary,optional (default=None)) – Node labels in a dictionary keyed by node of text labelsfont_size (
int,optional (default=12)) – Font size for text labelsfont_color (
string,optional (default=``’k’`` black)) – Font color stringfont_weight (
string,optional (default=``’normal’``)) – Font weightfont_family (
string,optional (default=``’sans-serif’``)) – Font familylabel (
string, optional) – Label for graph legend
Notes
For directed graphs, arrows are drawn at the head end. Arrows can be turned off with keyword arrows=False.
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 of axis
Also see the NetworkX drawing examples at https://networkx.github.io/documentation/latest/auto_examples/index.html