Plotting API#

The main user-facing functions are:

  • iplotx.networkto visualise networks/graphs and graph groupings (covers and clusterings)

  • iplotx.tree to visualise trees.

Tip

iplotx.plot and iplotx.graph are synonyms for iplotx.network.

Warning

iplotx.plot is deprecated and will be removed in future versions. Please use iplotx.network instead.

iplotx.network(network: Any | None = None, layout: str | Sequence[Sequence[float]] | ndarray | DataFrame | dict[Hashable, Sequence[float] | tuple[float, float]] | None = None, grouping: Sequence[set] | Sequence[int] | Sequence[str] | dict[str, set] | None = None, vertex_labels: list | dict | Series | bool | None = None, node_labels: list | dict | Series | bool | None = None, edge_labels: Sequence | None = None, ax: Axes | None = None, style: str | dict | Sequence[str | dict] = (), title: str | None = None, aspect: float | str | None = None, margins: float | tuple[float, float] | tuple[float, float, float] = 0, strip_axes: bool = True, figsize: tuple[float, float] | None = None, show: bool | None = None, **kwargs) list[Artist][source]#

Plot this network and/or vertex grouping using the specified layout.

Parameters:
  • network – The network to plot. Can be a networkx or igraph graph.

  • layout – The layout to use for plotting. If None, a layout will be looked for in the network object and, if none is found, an exception is raised. Defaults to None.

  • vertex_labels – The labels for the vertices. If None or False, no vertex labels will be drawn. If a list, the labels are taken from the list. If a dict, the keys should be the vertex IDs and the values should be the labels. If True (a single bool value), the vertex IDs will be used as labels.

  • node_labels – Same meaning as vertex_labels. This is an alias to help users who prefer the word “node” over “vertex”. If both vertex_labels and node_labels are specified, “node_labels” overrides “vertex_labels”.

  • edge_labels – The labels for the edges. If None, no edge labels will be drawn. Defaults to None.

  • ax – The axis to plot on. If None, a new figure and axis will be created. Defaults to None.

  • style – Apply this style for the objects to plot. This can be a sequence (e.g. list) of styles and they will be applied in order.

  • title – If not None, set the axes title to this value.

  • aspect – If not None, set the aspect ratio of the axis to this value. In 2D, the most common value is 1.0, which proportionates x- and y-axes. In 3D, only string values are accepted (see the documentation of Axes.set_aspect).

  • margins – How much margin to leave around the plot. A higher value (e.g. 0.1) can be used as a quick fix when some vertex shapes reach beyond the plot edge. This is a fraction of the data limits, so 0.1 means 10% of the data limits will be left as margin. A pair (in 2D) or triplet (in 3D) of floats can also be provided and applied to each axis separately.

  • strip_axes – If True, remove axis spines and ticks. In 3D, only ticks are removed.

  • figsize – If ax is None, a new matplotlib Figure is created. This argument specifies the (width, height) dimension of the figure in inches. If ax is not None, this argument is ignored. If None, the default matplotlib figure size is used.

  • show – If True, call plt.show() after plotting. If False, do not call plt.show(). If None (default), try to guess based on the environment and do not show in case of doubt.

  • kwargs – Additional arguments are treated as an alternate way to specify style. If both “style” and additional **kwargs are provided, they are both applied in that order (style, then **kwargs).

Returns:

A list of mpl.artist.Artist objects, set as a direct child of the matplotlib Axes. The list can have one or two elements, depending on whether you are requesting to plot a network, a grouping, or both.

NOTE: If your plots are now showing to screen, try passing show=True.

iplotx.tree(tree: Any | None = None, layout: str | Sequence[Sequence[float]] | ndarray | DataFrame | dict[Hashable, Sequence[float] | tuple[float, float]] = 'horizontal', directed: bool | str = False, vertex_labels: list | dict | Series | bool | None = None, node_labels: list | dict | Series | bool | None = None, leaf_labels: list | dict | Series | bool | None = None, show_support: bool = False, ax: Axes | None = None, style: str | dict | Sequence[str | dict] = 'tree', title: str | None = None, aspect: float | str | None = None, margins: float | tuple[float, float] = 0, strip_axes: bool = True, figsize: tuple[float, float] | None = None, show: bool | None = None, **kwargs) TreeArtist[source]#

Plot a tree using the specified layout.

Parameters:
  • tree – The tree to plot. Can be a BioPython.Phylo.Tree object.

  • layout – The layout to use for plotting.

  • directed – If False, do not draw arrows.

  • vertex_labels – The labels for the vertices. If None or False, no vertex labels. Also read leaf_labels for leaf nodes.

  • node_labels – Same meaning as vertex_labels. This is an alias to help users who prefer the word “node” over “vertex”. If both vertex_labels and node_labels are specified, “node_labels” overrides “vertex_labels”.

  • leaf_labels – The labels for the leaf nodes. If None or False, no leaf labels are used except if vertex_labels are specified for leaf nodes. This argument and the previous vertex_labels provide somewhat redundant functionality but have quite different default behaviours for distinct use cases. This argument is typically useful for labels that are specific to leaf nodes only (e.g. species in a phylogenetic tree), whereas vertex_labels is typically used for labels that apply to internal nodes too (e.g. branch support values). This redundancy is left on purpose to allow for maximal style flexibility.

  • show_support – If True, show the support values for the nodes (assumed to be from 0 to 100, rounded to nearest integer). If both this parameter and vertex_labels are set, show_support takes precedence and hides the vertex labels.

  • ax – The axis to plot on. If None, a new figure and axis will be created. Defaults to None.

  • style – Apply this style for the objects to plot. This can be a sequence (e.g. list) of styles and they will be applied in order.

  • title – If not None, set the axes title to this value.

  • aspect – If not None, set the aspect ratio of the axis to this value. The most common value is 1.0, which proportionates x- and y-axes.

  • margins – How much margin to leave around the plot. A higher value (e.g. 0.1) can be used as a quick fix when some vertex shapes reach beyond the plot edge. This is a fraction of the data limits, so 0.1 means 10% of the data limits will be left as margin.

  • strip_axes – If True, remove axis spines and ticks.

  • figsize – If ax is None, a new matplotlib Figure is created. This argument specifies the (width, height) dimension of the figure in inches. If ax is not None, this argument is ignored. If None, the default matplotlib figure size is used.

  • show – If True, call plt.show() after plotting. If False, do not call plt.show(). If None (default), try to guess based on the environment and do not show in case of doubt.

  • kwargs – Additional arguments are treated as an alternate way to specify style. If both “style” and additional **kwargs are provided, they are both applied in that order (style, then **kwargs).

Returns:

A TreeArtist object, set as a direct child of the matplotlib Axes.

NOTE: If your plots are now showing to screen, try passing show=True.