Skip to main content
`Ctrl`+`K`

# draw_networkx

draw_networkx(G, pos=None, arrows=None, with_labels=True, **kwds)

  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 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`, directed graphs draw arrowheads with `FancyArrowPatch`, while undirected graphs draw edges via `LineCollection` for speed. If `True`, draw arrowheads with FancyArrowPatches (bendable and stylish). If `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 `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`: `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 color (default=’k’ black)

      Font color string. Color can be string or rgb (or rgba) tuple of floats from 0-1.

    font_weight string (default=’normal’)

      Font weight

    font_family string (default=’sans-serif’)

      Font family

    label string, optional

      Label for graph legend

    hide_ticks bool, optional

      Hide ticks of axes. When `True` (the default), ticks and ticklabels are removed from the axes. To set ticks and tick labels to the pyplot default, use `hide_ticks=False`.

    kwds optional keywords

      See networkx.draw_networkx_nodes(), networkx.draw_networkx_edges(), and networkx.draw_networkx_labels() for a description of optional keywords.

  See also

  `draw`
  `draw_networkx_nodes`
  `draw_networkx_edges`
  `draw_networkx_labels`
  `draw_networkx_edge_labels`

  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 off axis

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