xgi.drawing.draw

Draw hypergraphs and simplicial complexes with matplotlib.

Functions

xgi.drawing.draw.draw(H, pos=None, ax=None, node_fc='white', node_ec='black', node_lw=1, node_size=7, node_shape='o', node_fc_cmap='Reds', vmin=None, vmax=None, max_order=None, dyad_color='black', dyad_lw=1.5, dyad_style='solid', dyad_color_cmap='Greys', dyad_vmin=None, dyad_vmax=None, edge_fc=None, edge_fc_cmap='crest_r', edge_vmin=None, edge_vmax=None, alpha=0.4, hull=False, radius=0.05, node_labels=False, hyperedge_labels=False, rescale_sizes=True, aspect='equal', **kwargs)[source]

Draw hypergraph or simplicial complex.

Parameters:
  • H (Hypergraph or SimplicialComplex.) – Hypergraph to draw

  • pos (dict, optional) – If passed, this dictionary of positions node_id:(x,y) is used for placing the 0-simplices. If None (default), use the barycenter_spring_layout to compute the positions.

  • ax (matplotlib.pyplot.axes, optional) – Axis to draw on. If None (default), get the current axes.

  • node_fc (str, dict, iterable, or NodeStat, optional) – Color of the nodes. If str, use the same color for all nodes. If a dict, must contain (node_id: color_str) pairs. If other iterable, assume the colors are specified in the same order as the nodes are found in H.nodes. If NodeStat, use the colormap specified with node_fc_cmap. By default, “white”.

  • node_ec (str, dict, iterable, or NodeStat, optional) – Color of node borders. If str, use the same color for all nodes. If a dict, must contain (node_id: color_str) pairs. If other iterable, assume the colors are specified in the same order as the nodes are found in H.nodes. If NodeStat, use the colormap specified with node_ec_cmap. By default, “black”.

  • node_lw (int, float, dict, iterable, or NodeStat, optional) – Line width of the node borders in pixels. If int or float, use the same width for all node borders. If a dict, must contain (node_id: width) pairs. If iterable, assume the widths are specified in the same order as the nodes are found in H.nodes. If NodeStat, use a monotonic linear interpolation defined between min_node_lw and max_node_lw. By default, 1.

  • node_size (int, float, dict, iterable, or NodeStat, optional) – Radius of the nodes in pixels. If int or float, use the same radius for all nodes. If a dict, must contain (node_id: radius) pairs. If iterable, assume the radiuses are specified in the same order as the nodes are found in H.nodes. If NodeStat, use a monotonic linear interpolation defined between min_node_size and max_node_size. By default, 15.

  • node_shape (string, optional) – The shape of the node. Specification is as matplotlib.scatter marker. Default is “o”.

  • node_fc_cmap (colormap) – Colormap for mapping node colors. By default, “Reds”. Ignored, if node_fc is a str (single color).

  • vmin (float or None) – Minimum for the node_fc_cmap scaling. By default, None.

  • vmax (float or None) – Maximum for the node_fc_cmap scaling. By default, None.

  • max_order (int, optional) – Maximum of hyperedges to plot. If None (default), plots all orders.

  • dyad_color (str, dict, iterable, or EdgeStat, optional) – Color of the dyadic links. If str, use the same color for all edges. If a dict, must contain (edge_id: color_str) pairs. If iterable, assume the colors are specified in the same order as the edges are found in H.edges. If EdgeStat, use a colormap (specified with dyad_color_cmap) associated to it. By default, “black”.

  • dyad_lw (int, float, dict, iterable, or EdgeStat, optional) – Line width of edges of order 1 (dyadic links). If int or float, use the same width for all edges. If a dict, must contain (edge_id: width) pairs. If iterable, assume the widths are specified in the same order as the edges are found in H.edges. If EdgeStat, use a monotonic linear interpolation defined between min_dyad_lw and max_dyad_lw. By default, 1.5.

  • dyad_style (str or list of strings, optional) – Line style of the dyads, e.g. ‘-’, ‘–’, ‘-.’, ‘:’ or words like ‘solid’ or ‘dashed’. See matplotlib’s documentation for all accepted values. By default, “solid”.

  • dyad_color_cmap (matplotlib colormap) – Colormap used to map the dyad colors. By default, “Greys”.

  • dyad_vmin (float, optional) – Minimum and maximum for dyad colormap scaling. By default, None.

  • dyad_vmax (float, optional) – Minimum and maximum for dyad colormap scaling. By default, None.

  • edge_fc (color or list of colors or array-like or dict or EdgeStat, optional) –

    Color of the hyperedges. The accepted formats are the same as matplotlib’s scatter, with the addition of dict and IDStat. Those with colors: * single color as a string * single color as 3- or 4-tuple * list of colors of length len(ids) * dict of colors containing the ids as keys

    Those with numerical values (will be mapped to colors): * array of floats * dict of floats containing the ids as keys * IDStat containing the ids as keys

    If None (default), color by edge size.

  • edge_fc_cmap (matplotlib colormap) – Colormap used to map the edge colors. By default, “cres_r”.

  • edge_vmin (float, optional) – Minimum and maximum for edge colormap scaling. By default, None.

  • edge_vmax (float, optional) – Minimum and maximum for edge colormap scaling. By default, None.

  • alpha (float, optional) – The edge transparency. By default, 0.4.

  • hull (bool, optional) – Wether to draw hyperedes as convex hulls. By default, False.

  • radius (float, optional) – Radius margin around the nodes when drawing convex hulls. Ignored if hull is False. Default is 0.05.

  • node_labels (bool or dict, optional) – If True, draw ids on the nodes. If a dict, must contain (node_id: label) pairs. By default, False. The default node_size (7) is too small to display the default labels well. The user may need to set it to a size of a least 15.

  • hyperedge_labels (bool or dict, optional) – If True, draw ids on the hyperedges. If a dict, must contain (edge_id: label) pairs. By default, False.

  • aspect ({"auto", "equal"} or float, optional) – Set the aspect ratio of the axes scaling, i.e. y/x-scale. aspect is passed directly to matplotlib’s ax.set_aspect(). Default is equal. See full Set the aspect ratio of the axes scaling, i.e. y/x-scale. aspect is passed directly to matplotlib’s ax.set_aspect(). Default is equal. See full description at https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.set_aspect.html

  • rescale_sizes (bool, optional) – If True, linearly interpolate node_size, node_lw and dyad_lw between min/max values that can be changed in the other argument params. If those are single values, interpolate_sizes is ignored for it. By default, True.

  • **kwargs (optional args) – Alternate default values. Values that can be overwritten are the following: * “min_node_size” (default: 5) * “max_node_size” (default: 30) * “min_node_lw” (default: 0) * “max_node_lw” (default: 5) * “min_dyad_lw” (default: 1) * “max_dyad_lw” (default: 10)

Returns:

  • ax (matplotlib Axes) – Axes plotted on

  • collections (a tuple of 3 collections:) –

    • node_collectionmatplotlib PathCollection

      Collection containing the nodes

    • dyad_collectionmatplotlib LineCollection

      Collection containing the dyads

    • edge_collectionmatplotlib PathCollection

      Collection containing the edges

Examples

>>> import xgi
>>> H = xgi.Hypergraph()
>>> H.add_edges_from([[1,2,3],[3,4],[4,5,6,7],[7,8,9,10,11]])
>>> ax = xgi.draw(H, pos=xgi.barycenter_spring_layout(H))
xgi.drawing.draw.draw_bipartite(H, pos=None, ax=None, node_fc='white', node_ec='black', node_lw=1, node_size=7, node_shape='o', node_fc_cmap='Reds', edge_marker_fc=None, edge_marker_ec='black', edge_marker_lw=1, edge_marker_size=7, edge_marker_shape='s', edge_marker_fc_cmap='crest_r', max_order=None, dyad_color=None, dyad_lw=1, dyad_style='solid', dyad_color_cmap='crest_r', node_labels=None, hyperedge_labels=None, arrowsize=10, arrowstyle='->', connectionstyle='arc3', rescale_sizes=True, aspect='equal', **kwargs)[source]

Draw a hypergraph as a bipartite network.

Parameters:
  • H (Hypergraph or DiHypergraph) – The hypergraph to draw.

  • pos (tuple of two dicts, optional) – The tuple should contain a (1) dictionary of positions node_id:(x,y) for placing node markers, and (2) a dictionary of positions edge_id:(x,y) for placing the edge markers. If None (default), use the bipartite_spring_layout to compute the positions.

  • ax (matplotlib.pyplot.axes, optional) – Axis to draw on. If None (default), get the current axes.

  • node_fc (str, dict, iterable, or NodeStat, optional) – Color of the nodes. If str, use the same color for all nodes. If a dict, must contain (node_id: color_str) pairs. If other iterable, assume the colors are specified in the same order as the nodes are found in H.nodes. If NodeStat, use the colormap specified with node_fc_cmap. By default, “white”.

  • node_ec (str, dict, iterable, or NodeStat, optional) – Color of node borders. If str, use the same color for all nodes. If a dict, must contain (node_id: color_str) pairs. If other iterable, assume the colors are specified in the same order as the nodes are found in H.nodes. If NodeStat, use the colormap specified with node_ec_cmap. By default, “black”.

  • node_lw (int, float, dict, iterable, or NodeStat, optional) – Line width of the node borders in pixels. If int or float, use the same width for all node borders. If a dict, must contain (node_id: width) pairs. If iterable, assume the widths are specified in the same order as the nodes are found in H.nodes. If NodeStat, use a monotonic linear interpolation defined between min_node_lw and max_node_lw. By default, 1.

  • node_size (int, float, dict, iterable, or NodeStat, optional) – Radius of the nodes in pixels. If int or float, use the same radius for all nodes. If a dict, must contain (node_id: radius) pairs. If iterable, assume the radiuses are specified in the same order as the nodes are found in H.nodes. If NodeStat, use a monotonic linear interpolation defined between min_node_size and max_node_size. By default, 7.

  • node_shape (str, optional) – Marker used for the nodes. By default ‘o’ (circle marker).

  • node_fc_cmap (colormap) – Colormap for mapping node colors. By default, “Reds”. Ignored, if node_fc is a str (single color).

  • edge_marker_fc (str, dict, iterable, optional) – Filling color of the hyperedges (markers). If str, use the same color for all hyperedges. If a dict, must contain (hyperedge_id: color_str) pairs. If other iterable, assume the colors are specified in the same order as the hyperedges are found in H.edges. If None, colors markers by edge size. By default, None.

  • edge_marker_ec (str, dict, iterable, optional) – Edge color of the hyperedges (markers). If str, use the same color for all hyperedges. If a dict, must contain (hyperedge_id: color_str) pairs. If other iterable, assume the colors are specified in the same order as the hyperedges are found in H.edges. By default, “black”.

  • edge_marker_lw (int, float, dict, iterable, or EdgeStat, optional) – Line width of the edge marker borders in pixels. If int or float, use the same width for all edge marker borders. If a dict, must contain (edge_id: width) pairs. If iterable, assume the widths are specified in the same order as the nodes are found in H.edges. If EdgeStat, use a monotonic linear interpolation defined between min_edge_marker_lw and max_edge_marker_lw. By default, 1.

  • edge_marker_size (int, float, dict, iterable, or EdgeStat, optional) – Radius of the edge markers in pixels. If int or float, use the same radius for all edge markers. If a dict, must contain (edge_id: radius) pairs. If iterable, assume the radii are specified in the same order as the edges are found in H.edges. If EdgeStat, use a monotonic linear interpolation defined between min_edge_marker_size and max_edge_marker_size. By default, 7.

  • edge_marker_shape (str, optional) – Marker used for the hyperedges. By default ‘s’ (square marker). If “”, no marker is displayed.

  • edge_marker_fc_cmap (colormap) – Colormap for mapping edge marker colors. By default, “Blues”. Ignored, if edge_marker_fc is a str (single color) or an iterable of colors.

  • max_order (int, optional) – Maximum of hyperedges to plot. If None (default), plots all orders.

  • dyad_color (str, dict, iterable, optional) – Color of the bipartite edges. If str, use the same color for all edges. If a dict, must contain (hyperedge_id: color_str) pairs. If other iterable, assume the colors are specified in the same order as the hyperedges are found in H.edges. By default, “black”.

  • dyad_lw (int, float, dict, iterable, optional) – Line width of the bipartite edges. If int or float, use the same width for all hyperedges. If a dict, must contain (hyperedge_id: width) pairs. If other iterable, assume the widths are specified in the same order as the hyperedges are found in H.edges. By default, 1.

  • dyad_style (str or list of strings, optional) – Line style of the dyads, e.g. ‘-’, ‘–’, ‘-.’, ‘:’ or words like ‘solid’ or ‘dashed’. See matplotlib’s documentation for all accepted values. By default, “solid”.

  • dyad_color_cmap (colormap) – Colormap for mapping bipartite edge colors. By default, “Greys”. Ignored, if dyad_color is a str (single color) or an iterable of colors.

  • node_labels (bool or dict, optional) – If True, draw ids on the nodes. If a dict, must contain (node_id: label) pairs. By default, False.

  • hyperedge_labels (bool or dict, optional) – If True, draw ids on the hyperedges. If a dict, must contain (edge_id: label) pairs. By default, False.

  • arrowsize (int (default=10)) – Size of the arrow head’s length and width. See matplotlib.patches.FancyArrowPatch for attribute mutation_scale for more info. Only used if the higher-order network is a DiHypergraph.

  • arrowstyle (str, optional) – By default: ‘->’. See matplotlib.patches.ArrowStyle for more options. Only used if the higher-order network is a DiHypergraph.

  • connectionstyle (string (default="arc3")) – Pass the connectionstyle parameter to create curved arc of rounding radius rad. For example, connectionstyle=’arc3,rad=0.2’. See matplotlib.patches.ConnectionStyle and matplotlib.patches.FancyArrowPatch for more info. Only used if the higher-order network is a DiHypergraph.

  • rescale_sizes (bool, optional) – If True, linearly interpolate node_size and between min/max values that can be changed in the other argument params. If node_size is a single value, this is ignored. By default, True.

  • aspect ({"auto", "equal"} or float, optional) – Set the aspect ratio of the axes scaling, i.e. y/x-scale. aspect is passed directly to matplotlib’s ax.set_aspect(). Default is equal. See full description at https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.set_aspect.html

  • **kwargs (optional args) – Alternate default values. Values that can be overwritten are the following: * min_node_size (default: 5) * max_node_size (default: 30) * min_node_lw (default: 0) * max_node_lw (default: 5) * min_edge_marker_size (default: 5) * max_edge_marker_size (default: 30) * min_edge_marker_lw (default: 0) * max_edge_marker_lw (default: 5) * min_dyad_lw (default: 1) * max_dyad_lw (default: 10) * min_source_margin (default: 0) * min_target_margin (default: 0)

Returns:

  • ax (matplotlib.pyplot.axes) – The axes corresponding the visualization

  • collections (a tuple of 3 collections:) –

    • node_collectionmatplotlib PathCollection

      Collection containing the nodes

    • edge_marker_collectionmatplotlib PathCollection

      Collection containing the edge markers

    • dyad_collectionmatplotlib LineCollection if undirected,

      list of FancyArrowPatches if not

      Collection containing the edges

Raises:

XGIError – If the network is not a Hypergraph, SimplicialComplex or a DiHypergraph.

See also

draw, draw_multilayer

xgi.drawing.draw.draw_multilayer(H, pos=None, ax=None, node_fc='white', node_ec='black', node_lw=1, node_size=5, node_shape='o', node_fc_cmap='Reds', vmin=None, vmax=None, dyad_color='grey', dyad_lw=1.5, dyad_style='solid', edge_fc=None, edge_fc_cmap='crest_r', edge_vmin=None, edge_vmax=None, alpha=0.4, layer_color='grey', layer_cmap='crest_r', max_order=None, conn_lines=True, conn_lines_style='dotted', h_angle=10, v_angle=20, sep=0.4, rescale_sizes=True, **kwargs)[source]

Draw a hypergraph or simplicial complex visualized in 3D showing hyperedges/simplices of different orders on superimposed layers.

Parameters:
  • H (Hypergraph or SimplicialComplex.) – Higher-order network to plot.

  • pos (dict or None, optional) – The positions of the nodes in the multilayer network. If None, a default layout will be computed using xgi.barycenter_spring_layout(). Default is None.

  • ax (matplotlib Axes3DSubplot or None, optional) – The subplot to draw the visualization on. If None, a new subplot will be created. Default is None.

  • node_fc (str, iterable, or NodeStat, optional) – Color of the nodes. If str, use the same color for all nodes. If other iterable, or NodeStat, assume the colors are specified in the same order as the nodes are found in H.nodes. By default, “white”.

  • node_ec (color or sequence of colors, optional) – Color of node borders. If color, use the same color for all nodes. If sequence of colors, assume the colors are specified in the same order as the nodes are found in H.nodes. By default, “black”.

  • node_lw (int, float, iterable, or NodeStat, optional) – Line width of the node borders in pixels. If int or float, use the same width for all node borders. If iterable or NodeStat, assume the widths are specified in the same order as the nodes are found in H.nodes. Values are clipped below and above by min_node_lw and max_node_lw, respectively. By default, 1.

  • node_size (int, float, iterable, or NodeStat, optional) – Radius of the nodes in pixels. If int or float, use the same radius for all nodes. If iterable or NodeStat, assume the radiuses are specified in the same order as the nodes are found in H.nodes. Values are clipped below and above by min_node_size and max_node_size, respectively. By default, 5.

  • node_shape (string, optional) – The shape of the node. Specification is as matplotlib.scatter marker. Default is “o”.

  • node_fc_cmap (colormap) – Colormap for mapping node colors. By default, “Reds”. Ignored, if node_fc is a str (single color).

  • vmin (float or None) – Minimum for the node_fc_cmap scaling. By default, None.

  • vmax (float or None) – Maximum for the node_fc_cmap scaling. By default, None.

  • dyad_color (color or list of colors) – Color of the dyadic links. If str, use the same color for all edges. If iterable, assume the colors are specified in the same order as the edges are found in H.edges. By default, “black”.

  • dyad_lw (int, float, dict, iterable, or EdgeStat, optional) – Line width of edges of order 1 (dyadic links). If int or float, use the same width for all edges. If a dict, must contain (edge_id: width) pairs. If iterable, assume the widths are specified in the same order as the edges are found in H.edges. If EdgeStat, use a monotonic linear interpolation defined between min_dyad_lw and max_dyad_lw. By default, 1.5.

  • dyad_style (str or list of strings, optional) – Line style of the dyads, e.g. ‘-’, ‘–’, ‘-.’, ‘:’ or words like ‘solid’ or ‘dashed’. See matplotlib’s documentation for all accepted values. By default, “solid”.

  • edge_fc (color or list of colors or array-like or dict or EdgeStat, optional) – Color of the hyperedges. The accepted formats are the same as matplotlib’s scatter, with the addition of dict and IDStat. Those with colors: * single color as a string * single color as 3- or 4-tuple * list of colors of length len(ids) * dict of colors containing the ids as keys Those with numerical values (will be mapped to colors): * array of floats * dict of floats containing the ids as keys * IDStat containing the ids as keys If None (default), color by edge size.

  • edge_fc_cmap (matplotlib colormap, optional) – Colormap used to map the edge colors. By default, “crest_r”.

  • edge_vmin (float, optional) – Minimum and maximum for edge colormap scaling. By default, None.

  • edge_vmax (float, optional) – Minimum and maximum for edge colormap scaling. By default, None.

  • alpha (float, optional) – The edge transparency. By default, 0.4.

  • layer_color (color or list of colors, optional) – Color of layers. By default, “grey”.

  • layer_cmap (colormap, optional) – Colormap to use in case of numerical values in layer_color. Ignored if layer_color does not contain numerical values to be mapped. By default, “crest_r”, but ignored.

  • max_order (int, optional) – Maximum of hyperedges to plot. If None (default), plots all orders.

  • conn_lines (bool, optional) – Whether to draw connections between layers. Default is True.

  • conn_lines_style (str, optional) – The linestyle of the connections between layers. Default is ‘dotted’.

  • h_angle (float, optional) – The rotation angle around the horizontal axis in degrees. Default is 10.

  • v_angle (float, optional) – The rotation angle around the vertical axis in degrees. Default is 0.

  • sep (float, optional) – The separation between layers. Default is 0.4.

  • **kwargs (optional args) – Alternate default values. Values that can be overwritten are the following: * “min_node_size” (default: 10) * “max_node_size” (default: 30) * “min_node_lw” (default: 2) * “max_node_lw” (default: 10) * “min_dyad_lw” (default: 1) * “max_dyad_lw” (default: 5)

Returns:

  • ax (matplotlib Axes3DSubplot) – The subplot with the multilayer network visualization.

  • collections (a tuple of 2 collections:) –

    • node_collectionmatplotlib PathCollection

      Collection containing the nodes one the top layer

    • edge_collectionmatplotlib PathCollection

      Collection containing the edges of size > 2

xgi.drawing.draw.draw_nodes(H, pos=None, ax=None, node_fc='white', node_ec='black', node_lw=1, node_size=7, node_shape='o', node_fc_cmap='Reds', vmin=None, vmax=None, zorder=None, params={}, node_labels=False, rescale_sizes=True, **kwargs)[source]

Draw the nodes of a hypergraph

Parameters:
  • H (Hypergraph or SimplicialComplex) – Higher-order network to plot.

  • pos (dict, optional) – If passed, this dictionary of positions node_id:(x,y) is used for placing the 0-simplices. If None (default), use the barycenter_spring_layout to compute the positions.

  • ax (matplotlib.pyplot.axes, optional) – Axis to draw on. If None (default), get the current axes.

  • node_fc (str, iterable, or NodeStat, optional) – Color of the nodes. If str, use the same color for all nodes. If other iterable, or NodeStat, assume the colors are specified in the same order as the nodes are found in H.nodes. By default, “white”.

  • node_ec (color or sequence of colors, optional) – Color of node borders. If color, use the same color for all nodes. If sequence of colors, assume the colors are specified in the same order as the nodes are found in H.nodes. By default, “black”.

  • node_lw (int, float, iterable, or NodeStat, optional) – Line width of the node borders in pixels. If int or float, use the same width for all node borders. If iterable or NodeStat, assume the widths are specified in the same order as the nodes are found in H.nodes. Values are clipped below and above by min_node_lw and max_node_lw, respectively. By default, 1.

  • node_size (int, float, iterable, or NodeStat, optional) – Radius of the nodes in pixels. If int or float, use the same radius for all nodes. If iterable or NodeStat, assume the radiuses are specified in the same order as the nodes are found in H.nodes. Values are clipped below and above by min_node_size and max_node_size, respectively. By default, 15.

  • node_shape (string, optional) – The shape of the node. Specification is as matplotlib.scatter marker. Default is “o”.

  • node_fc_cmap (colormap) – Colormap for mapping node colors. By default, “Reds”. Ignored, if node_fc is a str (single color).

  • vmin (float or None) – Minimum for the node_fc_cmap scaling. By default, None.

  • vmax (float or None) – Maximum for the node_fc_cmap scaling. By default, None.

  • zorder (int) – The layer on which to draw the nodes.

  • node_labels (bool or dict) – If True, draw ids on the nodes. If a dict, must contain (node_id: label) pairs. The default node_size (7) is too small to display the default labels well. The user may need to set it to a size of a least 15.

  • rescale_sizes (bool, optional) – If True, linearly interpolate node_size and node_lw between min/max values (5/30 for size, 0/5 for lw) that can be changed in the other argument params. If node_size (node_lw) is a single value, interpolate_sizes is ignored for it. By default, True.

  • params (dict) – Default parameters used if rescale_sizes is True. Keys to override default settings: * “min_node_size” (default: 5) * “max_node_size” (default: 30) * “min_node_lw” (default: 0) * “max_node_lw” (default: 5)

  • kwargs (optional keywords) – See draw_node_labels for a description of optional keywords.

Returns:

  • ax (matplotlib Axes) – Axes plotted on

  • node_collection (matplotlib PathCollection) – Collection containing the nodes

Notes

If nodes are colored with a cmap, the node_collection returned can be used to easily plot a colorbar corresponding to the node colors. Simply do plt.colorbar(node_collection).

Nodes with nonfinite node_fc (i.e. inf, -inf or nan are drawn with the bad colormap color (see plotnonfinitebool in plt.scatter and Colormap.set_bad from Matplotlib).

xgi.drawing.draw.draw_hyperedges(H, pos=None, ax=None, dyad_color='black', dyad_lw=1.5, dyad_style='solid', dyad_color_cmap='Greys', dyad_vmin=None, dyad_vmax=None, edge_fc=None, edge_fc_cmap='crest_r', edge_vmin=None, edge_vmax=None, alpha=0.4, max_order=None, params={}, hyperedge_labels=False, hull=False, radius=0.05, rescale_sizes=True, **kwargs)[source]

Draw hyperedges.

Parameters:
  • H (Hypergraph) – Hypergraph to plot

  • pos (dict, optional) – If passed, this dictionary of positions node_id:(x,y) is used for placing the 0-simplices. If None (default), use the barycenter_spring_layout to compute the positions.

  • ax (matplotlib.pyplot.axes, optional) – Axis to draw on. If None (default), get the current axes.

  • dyad_color (str, dict, iterable, or EdgeStat, optional) – Color of the dyadic links. If str, use the same color for all edges. If a dict, must contain (edge_id: color_str) pairs. If iterable, assume the colors are specified in the same order as the edges are found in H.edges. If EdgeStat, use a colormap (specified with dyad_color_cmap) associated to it. By default, “black”.

  • dyad_lw (int, float, dict, iterable, or EdgeStat, optional) – Line width of edges of order 1 (dyadic links). If int or float, use the same width for all edges. If a dict, must contain (edge_id: width) pairs. If iterable, assume the widths are specified in the same order as the edges are found in H.edges. If EdgeStat, use a monotonic linear interpolation defined between min_dyad_lw and max_dyad_lw. By default, 1.5.

  • dyad_style (str or list of strings, optional) – Line style of the dyads, e.g. ‘-’, ‘–’, ‘-.’, ‘:’ or words like ‘solid’ or ‘dashed’. See matplotlib’s documentation for all accepted values. By default, “solid”.

  • dyad_color_cmap (matplotlib colormap) – Colormap used to map the dyad colors. By default, “Greys”.

  • dyad_vmin (float, optional) – Minimum and maximum for dyad colormap scaling. By default, None.

  • dyad_vmax (float, optional) – Minimum and maximum for dyad colormap scaling. By default, None.

  • edge_fc (color or list of colors or array-like or dict or EdgeStat, optional) –

    Color of the hyperedges. The accepted formats are the same as matplotlib’s scatter, with the addition of dict and IDStat. Those with colors: * single color as a string * single color as 3- or 4-tuple * list of colors of length len(ids) * dict of colors containing the ids as keys

    Those with numerical values (will be mapped to colors): * array of floats * dict of floats containing the ids as keys * IDStat containing the ids as keys

    If None (default), color by edge size.

  • edge_fc_cmap (matplotlib colormap) – Colormap used to map the edge colors. By default, “crest_r”.

  • edge_vmin (float, optional) – Minimum and maximum for edge colormap scaling. By default, None.

  • edge_vmax (float, optional) – Minimum and maximum for edge colormap scaling. By default, None.

  • alpha (float, optional) – The edge transparency. By default, 0.4.

  • max_order (int, optional) – Maximum of hyperedges to plot. By default, None.

  • hyperedge_labels (bool or dict, optional) – If True, draw ids on the hyperedges. If a dict, must contain (edge_id: label) pairs. By default, None.

  • hull (bool, optional) – Wether to draw hyperedes as convex hulls. By default, False.

  • radius (float, optional) – Radius margin around the nodes when drawing convex hulls. Ignored if hull is False. Default is 0.05.

  • rescale_sizes (bool, optional) – If True, linearly interpolate dyad_lw and between min/max values (1/10) that can be changed in the other argument params. If dyad_lw is a single value, interpolate_sizes is ignored for it. By default, True.

  • params (dict) – Default parameters. Keys that may be useful to override default settings: * “min_dyad_lw” (default: 1) * “max_dyad_lw” (default: 10)

  • kwargs (optional keywords) – See draw_hyperedge_labels for a description of optional keywords.

Returns:

  • ax (matplotlib Axes) – Axes plotted on

  • collections (a tuple of 2 collections:) –

    • dyad_collectionmatplotlib LineCollection

      Collection containing the dyads

    • edge_collectionmatplotlib PathCollection

      Collection containing the edges

Raises:

XGIError – If a SimplicialComplex is passed.

xgi.drawing.draw.draw_undirected_dyads(H, pos=None, ax=None, max_order=None, dyad_color=None, dyad_lw=1, dyad_style='solid', dyad_color_cmap='crest_r', rescale_sizes=True, **kwargs)[source]

Draw the bipartite edges of an undirected hypergraph.

Parameters:
  • H (Hypergraph) – The hypergraph to draw.

  • pos (tuple of two dicts, optional) – The tuple should contains a (1) dictionary of positions node_id:(x,y) for placing node markers, and (2) a dictionary of positions edge_id:(x,y) for placing the edge markers. If None (default), use the bipartite_spring_layout to compute the positions.

  • ax (matplotlib.pyplot.axes, optional) – Axis to draw on. If None (default), get the current axes.

  • max_order (int, optional) – Maximum of hyperedges to plot. If None (default), plots all orders.

  • dyad_color (str, dict, iterable, optional) – Color of the bipartite edges. If str, use the same color for all edges. If a dict, must contain (hyperedge_id: color_str) pairs. If other iterable, assume the colors are specified in the same order as the hyperedges are found in H.edges. By default, “black”.

  • dyad_lw (int, float, dict, iterable, optional) – Line width of the bipartite edges. If int or float, use the same width for all hyperedges. If a dict, must contain (hyperedge_id: width) pairs. If other iterable, assume the widths are specified in the same order as the hyperedges are found in H.edges. By default, 1.

  • dyad_style (str or list of strings, optional) – Line style of the dyads, e.g. ‘-’, ‘–’, ‘-.’, ‘:’ or words like ‘solid’ or ‘dashed’. See matplotlib’s documentation for all accepted values. By default, “solid”.

  • dyad_color_cmap (colormap) – Colormap for mapping bipartite edge colors. By default, “Greys”. Ignored, if dyad_color is a str (single color) or an iterable of colors.

  • rescale_sizes (bool, optional) – If True, linearly interpolate node_size and between min/max values that can be changed in the other argument params. If node_size is a single value, this is ignored. By default, True.

  • **kwargs (optional args) – Alternate default values. Values that can be overwritten are the following: * min_dyad_lw (default: 1) * max_dyad_lw (default: 10)

Returns:

  • ax (matplotlib.pyplot.axes) – The axes corresponding the visualization

  • * dyad_collection (matplotlib LineCollection) – of bipartite edges

Raises:

XGIError – If DiHypergraph is passed.

xgi.drawing.draw.draw_directed_dyads(H, pos=None, ax=None, max_order=None, dyad_color=None, dyad_lw=1, dyad_style='solid', dyad_color_cmap='crest_r', arrowsize=10, arrowstyle='->', connectionstyle='arc3', node_size=5, node_shape='o', edge_marker_size=5, edge_marker_shape='s', rescale_sizes=True, **kwargs)[source]

Draw the bipartite edges of a directed hypergraph.

Parameters:
  • H (DiHypergraph) – The hypergraph to draw.

  • pos (tuple of two dicts, optional) – The tuple should contains a (1) dictionary of positions node_id:(x,y) for placing node markers, and (2) a dictionary of positions edge_id:(x,y) for placing the edge markers. If None (default), use the bipartite_spring_layout to compute the positions.

  • ax (matplotlib.pyplot.axes, optional) – Axis to draw on. If None (default), get the current axes.

  • max_order (int, optional) – Maximum of hyperedges to plot. If None (default), plots all orders.

  • dyad_color (str, dict, iterable, optional) – Color of the bipartite edges. If str, use the same color for all edges. If a dict, must contain (hyperedge_id: color_str) pairs. If other iterable, assume the colors are specified in the same order as the hyperedges are found in H.edges. By default, “black”.

  • dyad_lw (int, float, dict, iterable, optional) – Line width of the bipartite edges. If int or float, use the same width for all hyperedges. If a dict, must contain (hyperedge_id: width) pairs. If other iterable, assume the widths are specified in the same order as the hyperedges are found in H.edges. By default, 1.

  • dyad_style (str or list of strings, optional) – Line style of the dyads, e.g. ‘-’, ‘–’, ‘-.’, ‘:’ or words like ‘solid’ or ‘dashed’. See matplotlib’s documentation for all accepted values. By default, “solid”.

  • dyad_color_cmap (colormap) – Colormap for mapping bipartite edge colors. By default, “Greys”. Ignored, if dyad_color is a str (single color) or an iterable of colors.

  • arrowsize (int (default=10)) – Size of the arrow head’s length and width. See matplotlib.patches.FancyArrowPatch for attribute mutation_scale for more info. Only used if the higher-order network is a DiHypergraph.

  • arrowstyle (str, optional) – By default: ‘->’. See matplotlib.patches.ArrowStyle for more options. Only used if the higher-order network is a DiHypergraph.

  • connectionstyle (string (default="arc3")) – Pass the connectionstyle parameter to create curved arc of rounding radius rad. For example, connectionstyle=’arc3,rad=0.2’. See matplotlib.patches.ConnectionStyle and matplotlib.patches.FancyArrowPatch for more info. Only used if the higher-order network is a DiHypergraph.

  • rescale_sizes (bool, optional) – If True, linearly interpolate node_size and between min/max values that can be changed in the other argument params. If node_size is a single value, this is ignored. By default, True.

  • node_size (int, float, dict, iterable, or NodeStat, optional) – Radius of the nodes in pixels. If int or float, use the same radius for all nodes. If a dict, must contain (node_id: radius) pairs. If iterable, assume the radiuses are specified in the same order as the nodes are found in H.nodes. If NodeStat, use a monotonic linear interpolation defined between min_node_size and max_node_size. Used for arrow spacing. By default, 7.

  • node_shape (str, optional) – Marker used for the nodes. Used for arrow spacing. By default ‘o’ (circle marker).

  • edge_marker_size (int, float, dict, iterable, or EdgeStat, optional) – Radius of the edge markers in pixels. If int or float, use the same radius for all edge markers. If a dict, must contain (edge_id: radius) pairs. If iterable, assume the radii are specified in the same order as the edges are found in H.edges. If EdgeStat, use a monotonic linear interpolation defined between min_edge_marker_size and max_edge_marker_size. Used for arrow spacing. By default, 7.

  • edge_marker_shape (str, optional) – Marker used for the hyperedges. If “”, no marker is displayed. Used for arrow spacing. By default ‘s’ (square marker).

  • **kwargs (optional args) – Alternate default values. Values that can be overwritten are the following: * min_dyad_lw (default: 1) * max_dyad_lw (default: 10)

Returns:

  • ax (matplotlib.pyplot.axes) – The axes corresponding the visualization

  • dyad_collection (list of FancyArrowPatches) – representing directed bipartite edges

Raises:

XGIError – If something different than a DiHypergraph is passed.

xgi.drawing.draw.draw_simplices(SC, pos=None, ax=None, dyad_color='black', dyad_lw=1.5, dyad_style='solid', dyad_color_cmap='Greys', dyad_vmin=None, dyad_vmax=None, edge_fc=None, edge_fc_cmap='crest_r', edge_vmin=None, edge_vmax=None, alpha=0.4, max_order=None, params={}, hyperedge_labels=False, rescale_sizes=True, **kwargs)[source]

Draw maximal simplices and pairwise faces.

Parameters:
  • SC (SimplicialComplex) – Simplicial complex to draw

  • pos (dict, optional) – If passed, this dictionary of positions node_id:(x,y) is used for placing the 0-simplices. If None (default), use the barycenter_spring_layout to compute the positions.

  • ax (matplotlib.pyplot.axes, optional) – Axis to draw on. If None (default), get the current axes.

  • dyad_color (str, dict, iterable, or EdgeStat, optional) – Color of the dyadic links. If str, use the same color for all edges. If a dict, must contain (edge_id: color_str) pairs. If iterable, assume the colors are specified in the same order as the edges are found in H.edges. If EdgeStat, use a colormap (specified with dyad_color_cmap) associated to it. By default, “black”.

  • dyad_lw (int, float, dict, iterable, or EdgeStat, optional) – Line width of edges of order 1 (dyadic links). If int or float, use the same width for all edges. If a dict, must contain (edge_id: width) pairs. If iterable, assume the widths are specified in the same order as the edges are found in H.edges. If EdgeStat, use a monotonic linear interpolation defined between min_dyad_lw and max_dyad_lw. By default, 1.5.

  • dyad_style (str or list of strings, optional) – Line style of the dyads, e.g. ‘-’, ‘–’, ‘-.’, ‘:’ or words like ‘solid’ or ‘dashed’. See matplotlib’s documentation for all accepted values. By default, “solid”.

  • dyad_color_cmap (matplotlib colormap) – Colormap used to map the dyad colors. By default, “Greys”.

  • dyad_vmin (float, optional) – Minimum and maximum for dyad colormap scaling. By default, None.

  • dyad_vmax (float, optional) – Minimum and maximum for dyad colormap scaling. By default, None.

  • edge_fc (color or list of colors or array-like or dict or EdgeStat, optional) –

    Color of the hyperedges. The accepted formats are the same as matplotlib’s scatter, with the addition of dict and IDStat. Those with colors: * single color as a string * single color as 3- or 4-tuple * list of colors of length len(ids) * dict of colors containing the ids as keys

    Those with numerical values (will be mapped to colors): * array of floats * dict of floats containing the ids as keys * IDStat containing the ids as keys

    If None (default), color by edge size.

  • edge_fc_cmap (matplotlib colormap) – Colormap used to map the edge colors. By default, “crest_r”.

  • edge_vmin (float, optional) – Minimum and maximum for edge colormap scaling. By default, None.

  • edge_vmax (float, optional) – Minimum and maximum for edge colormap scaling. By default, None.

  • alpha (float, optional) – The edge transparency. By default, 0.4.

  • max_order (int, optional) – Maximum of hyperedges to plot. By default, None.

  • hyperedge_labels (bool or dict, optional) – If True, draw ids on the hyperedges. If a dict, must contain (edge_id: label) pairs. By default, None.

  • rescale_sizes (bool, optional) – If True, linearly interpolate dyad_lw and between min/max values (1/10) that can be changed in the other argument params. If dyad_lw is a single value, interpolate_sizes is ignored for it. By default, True.

  • params (dict) – Default parameters. Keys that may be useful to override default settings: * “min_dyad_lw” (default: 1) * “max_dyad_lw” (default: 10)

  • kwargs (optional keywords) – See draw_hyperedge_labels for a description of optional keywords.

Returns:

  • ax

  • collections (a tuple of 2 collections:) –

    • dyad_collectionmatplotlib LineCollection

      Collection containing the dyads

    • edge_collectionmatplotlib PathCollection

      Collection containing the edges

Raises:

XGIError – If a Hypergraph is passed.

xgi.drawing.draw.draw_node_labels(H, pos, node_labels=False, font_size_nodes=10, font_color_nodes='black', font_family_nodes='sans-serif', font_weight_nodes='normal', alpha_nodes=None, bbox_nodes=None, horizontalalignment_nodes='center', verticalalignment_nodes='center', ax_nodes=None, clip_on_nodes=True, zorder=None)[source]

Draw node labels on the hypergraph or simplicial complex.

Parameters:
  • H (Hypergraph or SimplicialComplex.) –

  • pos (dict) – Dictionary of positions node_id:(x,y).

  • node_labels (bool or dict, optional) – If True, draw ids on the nodes. If a dict, must contain (node_id: label) pairs. By default, False.

  • font_size_nodes (int, optional) – Font size for text labels, by default 10.

  • font_color_nodes (str, optional) – Font color string, by default “black”.

  • font_family_nodes (str, optional) – Font family, by default “sans-serif”.

  • font_weight_nodes (str (default='normal')) – Font weight.

  • alpha_nodes (float, optional) – The text transparency, by default None.

  • bbox_nodes (Matplotlib bbox, optional) – Specify text box properties (e.g. shape, color etc.) for node labels. When it is None (default), use Matplotlib’s ax.text default

  • horizontalalignment_nodes (str, optional) – Horizontal alignment {‘center’, ‘right’, ‘left’}. By default, “center”.

  • verticalalignment_nodes (str, optional) – Vertical alignment {‘center’, ‘top’, ‘bottom’, ‘baseline’, ‘center_baseline’}. By default, “center”.

  • ax_nodes (matplotlib.pyplot.axes, optional) – Draw the graph in the specified Matplotlib axes. By default, None.

  • clip_on_nodes (bool, optional) – Turn on clipping of node labels at axis boundaries. By default, True.

  • zorder (int, optional) – The vertical order on which to draw the labels. By default, None, in which case it is plotted above the last plotted object.

Returns:

dict of labels keyed by node id.

Return type:

dict

xgi.drawing.draw.draw_hyperedge_labels(H, pos, hyperedge_labels=False, font_size_edges=10, font_color_edges='black', font_family_edges='sans-serif', font_weight_edges='normal', alpha_edges=None, bbox_edges=None, horizontalalignment_edges='center', verticalalignment_edges='center', ax_edges=None, rotate_edges=False, clip_on_edges=True)[source]

Draw hyperedge labels on the hypegraph or simplicial complex.

Parameters:
  • H (Hypergraph.) –

  • pos (dict) – Dictionary of positions node_id:(x,y).

  • hyperedge_labels (bool or dict, optional) – If True, draw ids on the hyperedges. If a dict, must contain (edge_id: label) pairs. By default, False.

  • font_size_edges (int, optional) – Font size for text labels, by default 10.

  • font_color_edges (str, optional) – Font color string, by default “black”.

  • font_family_edges (str (default='sans-serif')) – Font family.

  • font_weight_edges (str (default='normal')) – Font weight.

  • alpha_edges (float, optional) – The text transparency, by default None.

  • bbox_edges (Matplotlib bbox, optional) – Specify text box properties (e.g. shape, color etc.) for edge labels. By default, {boxstyle=’round’, ec=(1.0, 1.0, 1.0), fc=(1.0, 1.0, 1.0)}

  • horizontalalignment_edges (str, optional) – Horizontal alignment {‘center’, ‘right’, ‘left’}. By default, “center”.

  • verticalalignment_edges (str, optional) – Vertical alignment {‘center’, ‘top’, ‘bottom’, ‘baseline’, ‘center_baseline’}. By default, “center”.

  • ax_edges (matplotlib.pyplot.axes, optional) – Draw the graph in the specified Matplotlib axes. By default, None.

  • rotate_edges (bool, optional) – Rotate edge labels for dyadic links to lie parallel to edges, by default False.

  • clip_on_edges (bool, optional) – Turn on clipping of hyperedge labels at axis boundaries, by default True.

Returns:

dict of labels keyed by hyperedge id.

Return type:

dict