### Quick Start with networkx Source: https://iplotx.readthedocs.io/en/latest/_sources/installing.md.txt Visualize a graph using iplotx with the networkx library. Requires networkx to be installed. ```python import networkx as nx import iplotx as ipx g = nx.Graph([(0, 1), (1, 2), (2, 3), (3, 4), (4, 0)]) layout = nx.layout.circular_layout(g) ipx.network(g, layout) ``` -------------------------------- ### Quick Start with igraph Source: https://iplotx.readthedocs.io/en/latest/_sources/installing.md.txt Visualize a graph using iplotx with the igraph library. Requires igraph to be installed. ```python import igraph as ig import iplotx as ipx g = ig.Graph.Ring(5) layout = g.layout("circle").coords ipx.network(g, layout) ``` -------------------------------- ### Install iplotx with ilayoutx Source: https://iplotx.readthedocs.io/en/latest/_sources/installing.md.txt Install iplotx along with ilayoutx for network layout computations. ```bash pip install iplotx ilayoutx ``` -------------------------------- ### Install iplotx Source: https://iplotx.readthedocs.io/en/latest/_sources/installing.md.txt Install the iplotx library using pip. ```bash pip install iplotx ``` -------------------------------- ### Showcase Network Plot Elements Source: https://iplotx.readthedocs.io/en/latest/gallery/style/plot_elements.html This example displays a network graph with various styling options applied to vertices, edges, and labels. It requires matplotlib and iplotx to be installed. ```python import matplotlib.pyplot as plt import iplotx as ipx network = { "edges": [(0, 1), (1, 2), (2, 3), (3, 0), (2, 2)], "directed": True, } layout = [(0, 0), (1, 0), (1, 1), (0, 1)] fig, ax = plt.subplots(figsize=(4.3, 4.3)) ipx.network( network, layout, ax=ax, vertex_labels=["Vertex\nlabel"] + [""] * 3, edge_labels=["", "", "Edge\nlabel", "", ""], vertex_label_bbox_edgecolor="k", vertex_label_bbox_linewidth=1.5, vertex_label_bbox_facecolor="steelblue", vertex_label_bbox_alpha=0.5, edge_label_bbox_edgecolor="k", edge_label_bbox_linewidth=1.5, edge_label_bbox_facecolor="tomato", edge_color=["k", "tomato", "k", "k", "k"], edge_arrow_color=["k", "darkred", "k", "k", "k"], edge_linewidth=[2, 4, 2, 2, 2], vertex_facecolor=["w"] * 3 + ["steelblue"], vertex_edgecolor="k", vertex_linewidth=2, vertex_size=[50, 25, 25, 50], vertex_marker="o", vertex_label_color="k", edge_curved=True, edge_tension=[0, 1.25, 0, 3.5], margins=(0, 0.08), ) ``` -------------------------------- ### Basic Network Plotting with iplotx Source: https://iplotx.readthedocs.io/en/latest/_sources/gallery/index.rst.txt This example demonstrates how to plot a simple graph using iplotx. ```python ... ``` -------------------------------- ### Visualize Branch Support Source: https://iplotx.readthedocs.io/en/latest/_downloads/ab47bbf2156acc6f1b3ebb544a401c2f/plot_support.ipynb Basic example to visualize branch support values on a phylogenetic tree. Requires cogent3 and matplotlib. ```python import cogent3 import matplotlib.pyplot as plt import iplotx as ipx tree = cogent3.load_tree("data/tree-with-support.json") fig, ax = plt.subplots(figsize=(5, 4)) art = ipx.tree( tree, ax=ax, leaf_labels=True, style="cogent3", show_support=True, ) ``` -------------------------------- ### Plotting a Simple Network with iplotx Source: https://iplotx.readthedocs.io/en/latest/providers.html Demonstrates how to visualize a network using a simple dictionary-based data provider and a layout dictionary. This example does not require external network analysis libraries. ```python import iplotx as ipx network = { "edges": [ ("alice", "bob"), ("bob", "jago"), ("alice", "jago"), ] } layout = { "alice": (0, 0), "bob": (1, 1), "jago": (1, 0), } ipx.plot( network, layout, ) ``` -------------------------------- ### Plotting a Simple Network with iplotx Source: https://iplotx.readthedocs.io/en/latest/_sources/providers.md.txt Demonstrates how to ingest and visualize a network using a simple dictionary format and a predefined layout. This example requires matplotlib, numpy, and pandas. ```python import iplotx as ipx network = { "edges": [ ("alice", "bob"), ("bob", "jago"), ("alice", "jago"), ] } layout = { "alice": (0, 0), "bob": (1, 1), "jago": (1, 0), } ipx.plot( network, layout, ) ``` -------------------------------- ### Basic Branch Support Visualization Source: https://iplotx.readthedocs.io/en/latest/gallery/tree/plot_support.html This snippet shows the basic usage of `iplotx.tree` to display branch support values. Ensure you have `cogent3` and `matplotlib` installed and a tree file with support data. ```python import cogent3 import matplotlib.pyplot as plt import iplotx as ipx tree = cogent3.load_tree("data/tree-with-support.json") fig, ax = plt.subplots(figsize=(5, 4)) art = ipx.tree( tree, ax=ax, leaf_labels=True, style="cogent3", show_support=True, ) ``` -------------------------------- ### Create and Plot a Simple Path Graph Source: https://iplotx.readthedocs.io/en/latest/_downloads/ae81a22c794f5dd9bb945db79b137431/plot_simple_path.ipynb Generates a path graph using networkx and visualizes it with iplotx. Ensure networkx and iplotx are installed and imported. The layout is seeded for reproducible results. ```python import networkx as nx import iplotx as ipx G = nx.path_graph(8) pos = nx.spring_layout(G, seed=47) # Seed layout for reproducibility ipx.network(G, layout=pos) ``` -------------------------------- ### Basic Cogent3 Tree Layout with iplotx Source: https://iplotx.readthedocs.io/en/latest/_downloads/ebaee9f96d315bd17e843740077d33ce/plot_cogent3_layouts.ipynb Reproduces a standard cogent3 tree layout using iplotx and matplotlib. Ensure cogent3 and iplotx are installed. ```python import cogent3 import matplotlib.pyplot as plt import iplotx as ipx tree = cogent3.load_tree("data/tree-with-support.json") fig, ax = plt.subplots(figsize=(5, 4)) art = ipx.tree( tree, ax=ax, leaf_labels=True, style="cogent3", ) ``` -------------------------------- ### Create and Visualize Network with Patches Source: https://iplotx.readthedocs.io/en/latest/gallery/network_science/plot_redblack.html Use this snippet to create a network graph with iplotx and overlay it with custom matplotlib patches. Ensure iplotx and matplotlib are installed. ```python import numpy as np import iplotx as ipx import matplotlib.pyplot as plt # We will use a network laid out onto a square grid gsize = 5 # Grid size layout = [(i % gsize, i // gsize) for i in range(gsize**2)] # Two possible colors colorlist = np.array(["tomato", "#111"]) # Assign node colors at random node_colors = colorlist[np.random.randint(2, size=gsize**2)] # Connect two neighboring nodes if they have the same color edges = [] for inode in range(gsize**2): i = inode // gsize j = inode % gsize # Four possible edges cands = [] if i != 0: cands.append(inode - gsize) if j != 0: cands.append(inode - 1) if i != gsize - 1: cands.append(inode + gsize) if j != gsize - 1: cands.append(inode + 1) for inode2 in cands: if node_colors[inode] == node_colors[inode2]: if (inode2, inode) not in edges: edges.append((inode, inode2)) # Build the network using our zero-dependency data structure network = { "edges": edges, "nodes": list(range(gsize**2)), } # Visualise the network fig, ax = plt.subplots(figsize=(5, 5)) ipx.network( network, layout=layout, ax=ax, vertex_size=8, vertex_marker='d', ) # Add square patches centered on each node for i in range(gsize): for j in range(gsize): inode = i * gsize + j ax.add_patch(plt.Rectangle( (j-0.5, i-0.5), 1, 1, facecolor=node_colors[inode], edgecolor="none", alpha=0.4, zorder=0, )) ``` -------------------------------- ### Basic Cogent3 Tree Layout Source: https://iplotx.readthedocs.io/en/latest/gallery/tree/plot_cogent3_layouts.html Reproduces a standard cogent3 tree layout using iplotx with matplotlib. Ensure cogent3 and matplotlib are installed. ```python import cogent3 import matplotlib.pyplot as plt import iplotx as ipx tree = cogent3.load_tree("data/tree-with-support.json") fig, ax = plt.subplots(figsize=(5, 4)) art = ipx.tree( tree, ax=ax, leaf_labels=True, style="cogent3", ) ``` -------------------------------- ### Directed Graph with Opposite Half Arrows (|") Source: https://iplotx.readthedocs.io/en/latest/_downloads/4befb45017dbf57dbc78b49693a2924c/plot_halfarrows.ipynb This example demonstrates using the opposite half arrow marker ('|\') by adjusting the `edge_paralleloffset` to a positive value. This creates a visual effect on the other side of the edge compared to the previous example. Use this when you need to visually distinguish opposing directions on the same edge. ```python fig, ax = plt.subplots(figsize=(3, 2.7)) ipx.network( g, layout=layout, ax=ax, edge_arrow_marker="|\\", edge_paralleloffset=7, edge_arrow_width=15, ) ``` -------------------------------- ### Plot Cogent3 Tree with Custom Leaf Labels and Margins Source: https://iplotx.readthedocs.io/en/latest/_downloads/ccf5f25334782fc9fe12bdab03b91aaf/plot_cogent3_tree.ipynb Plots a cogent3 tree with custom leaf labels and adjusted horizontal margins. This example utilizes matplotlib for figure and axes setup, and requires iplotx for plotting. ```python leaf_labels = {leaf: f"Species {i + 1}" for i, leaf in enumerate(tree.tips())} fig, ax = plt.subplots(figsize=(5, 4)) ipx.plotting.tree( tree, ax=ax, vertex_labels=leaf_labels, vertex_label_hmargin=10, ) ax.set_xlim(-0.2, 1.5) ``` -------------------------------- ### Plot Minimum Spanning Tree with Non-Rotating Labels Source: https://iplotx.readthedocs.io/en/latest/gallery/network_science/plot_minimum_spanning_trees.html This snippet visualizes the same graph and minimum spanning tree as the previous example, but with edge labels set to not rotate. This can be useful for improving readability in certain layouts. Ensure igraph and iplotx are installed. ```python ipx.network( g, layout=layout, edge_labels=g.es["weight"], style={ "vertex": { "facecolor": "lightblue", "edgecolor": "black", "linewidth": 1, }, "edge": { "linewidth": g.es["width"], "label": { "rotate": False, "bbox": { "facecolor": "white", "edgecolor": "none", }, }, }, }, ) ``` -------------------------------- ### Plot Radial ETE4 Tree with iplotx Source: https://iplotx.readthedocs.io/en/latest/_downloads/d12e10c1d169b29546615014f2d6dc6a/plot_ete4.ipynb Plots a radial layout of an ETE4 tree using iplotx. This example customizes the layout orientation, start angle, span, and styling for edges, leaves, and leaf edges. Leaf labels are also customized. ```python # sphinx_gallery_thumbnail_number = 2 ipx.plotting.tree( tree, layout="radial", layout_orientation="right", style=[ "tree", { "edge": { "color": "deeppink", "linewidth": 4, }, "layout": { "start": -180, "span": 180, }, "leaf": { "label": { "hmargin": 15, } }, "leafedge": { "color": "purple", "linewidth": 2, }, }, ], leaf_labels={leaf: str(i + 1) for i, leaf in enumerate(tree.leaves())}, aspect=1, margin=0.1, ) ``` -------------------------------- ### get_texts Source: https://iplotx.readthedocs.io/en/latest/api/artists.html Gets the texts of the labels. ```APIDOC ## get_texts ### Description Get the texts of the labels. ### Method `get_texts() -> list[str]` ### Returns - A list of strings, where each string is the text of a label. ``` -------------------------------- ### Plotting a Simple NetworkX Graph Source: https://iplotx.readthedocs.io/en/latest/_sources/gallery/network_science/index.rst.txt Demonstrates how to create and visualize a basic graph using NetworkX. ```python import networkx as nx import matplotlib.pyplot as plt G = nx.Graph() G.add_edges_from([(1, 2), (1, 3), (2, 3), (3, 4)]) pos = nx.spring_layout(G) nx.draw(G, pos, with_labels=True, node_color='skyblue', edge_color='gray', node_size=500, font_size=10) plt.title("Simple NetworkX Graph") plt.show() ``` -------------------------------- ### get_text Source: https://iplotx.readthedocs.io/en/latest/api/artists.html Gets the text of the labels. ```APIDOC ## get_text ### Description Get the texts of the labels. ### Method `get_text() -> str` ### Returns - The text of the labels. ``` -------------------------------- ### get_tensions Source: https://iplotx.readthedocs.io/en/latest/api/artists.html Gets the tension for the edges. ```APIDOC ## get_tensions() ### Description Get the tension for the edges. ### Returns The tension for the edges. If None, the edges are straight. ``` -------------------------------- ### Streamlined Double Tree Plotting with `ipx.doubletree` Source: https://iplotx.readthedocs.io/en/latest/_downloads/a7e412d92468d874cf4616f46df09a11/plot_double_tree.ipynb This example utilizes the `ipx.doubletree` function for a more concise way to plot two trees facing each other. It allows passing keyword arguments for left and right tree configurations separately. Note the adjusted coordinates for connecting lines due to the centered layout. ```python fig, ax = plt.subplots(figsize=(9, 4)) ipx.doubletree( tree1, tree2, ax=ax, kwargs_left=dict( leaf_deep=True, edge_color="tomato", ), kwargs_right=dict( leaf_deep=True, edge_color="steelblue", ), gap=2, aspect=1, ) # Add lines connecting corresponding leaves # NOTE: The layout is horizontally centered now matches = [ (0, 0), (1, 4), (2, 5), (3, 2), (4, 1), (5, 5), ] for y1, y2 in matches: ax.plot( [-0.3, 1.3], [y1, y2], color="gray", linewidth=2, ) ``` -------------------------------- ### Network Plot with Style Context Manager Source: https://iplotx.readthedocs.io/en/latest/_downloads/9137a05a2287cb684755c2ae08e9c463/plot_loops.ipynb This example shows how to apply styles to a network plot using a style context manager. Styles defined within the `with` block are applied to the network plot generated inside it. ```python with ipx.style.context( vertex_size=30, vertex_facecolor="lightblue", vertex_edgecolor="none", vertex_label_color="black", edge_linestyle=linestyle, edge_paralleloffset=0, edge_looptension=3.5, edge_arrow_marker="|>", ): ipx.network( G, layout=pos, vertex_labels=True, ) ``` -------------------------------- ### get_tension Source: https://iplotx.readthedocs.io/en/latest/api/artists.html Gets the tension for the edges. ```APIDOC ## get_tension() ### Description Get the tension for the edges. ### Returns The tension for the edges. If None, the edges are straight. ``` -------------------------------- ### Per-Edge Angular Styling with defaultdict Source: https://iplotx.readthedocs.io/en/latest/_downloads/3f6ccaf51acdd77ff4048719d9eaa22d/plot_angular_waypoints.ipynb This example shows how to apply angular styling on a per-edge basis using a defaultdict. It allows specific edges to have different waypoint behaviors, with a default fallback for unspecified edges. ```python from collections import defaultdict ipx.tree( tree, edge_waypoints=defaultdict(lambda: True, {tree.clade[0, 1]: False}), title="Mixed\n(per-edge)", ) ``` -------------------------------- ### get_ports Source: https://iplotx.readthedocs.io/en/latest/api/artists.html Gets the ports for all edges. ```APIDOC ## get_ports() ### Description Get the ports for all edges. ### Returns The ports for the edges, as a pair of strings or None for each edge. If None, it means all edges are free. ``` -------------------------------- ### get_looptension Source: https://iplotx.readthedocs.io/en/latest/api/artists.html Gets the tension for loops. ```APIDOC ## get_looptension() ### Description Get the tension for loops. ### Returns The tension for loops. If None, the default is 2.5. ``` -------------------------------- ### get_rotations Source: https://iplotx.readthedocs.io/en/latest/api/artists.html Gets the rotations of the labels in radians. ```APIDOC ## get_rotations ### Description Get the rotations of the labels in radians. ### Method `get_rotations() -> ndarray` ### Returns - A numpy ndarray containing the label rotations in radians. ``` -------------------------------- ### Apply Styles to Network Graph Elements Source: https://iplotx.readthedocs.io/en/latest/_sources/style.md.txt Demonstrates how to apply custom styles to specific graph elements like vertices using dictionaries. This example shows setting vertex sizes based on their IDs. ```python import networkx as nx import iplotx as ipx G = nx.Graph([(0, 1)]) ipx.network( G, vertex_size={0: 20, 1: 30}, ) ``` -------------------------------- ### get_offsets Source: https://iplotx.readthedocs.io/en/latest/api/artists.html Gets the positions (offsets) of the labels. ```APIDOC ## get_offsets ### Description Get the positions (offsets) of the labels. ### Method `get_offsets(_with_margins : bool = False_) -> ndarray` ### Parameters #### with_margins - **with_margins** (bool) - Whether to include margins. Defaults to False. ### Returns - A numpy ndarray containing the label offsets. ``` -------------------------------- ### get_datalim Source: https://iplotx.readthedocs.io/en/latest/api/artists.html Gets the data limits of the labels. ```APIDOC ## get_datalim ### Description Get the data limits of the labels. ### Method `get_datalim(_transData =None_) -> Bbox` ### Parameters #### transData - **transData**: Optional transform data. ### Returns - The data limits as a Bbox object. ``` -------------------------------- ### Access and Print the Default Style Source: https://iplotx.readthedocs.io/en/latest/_sources/style.md.txt This snippet demonstrates how to import and print the default style configuration provided by iplotx. ```python from iplotx.style import default as default_style print(default_style) ``` -------------------------------- ### Apply Styles using Keyword Arguments Source: https://iplotx.readthedocs.io/en/latest/gallery/basic/plot_loops.html This snippet shows how to apply styles directly as keyword arguments to the `ipx.network` function, offering a more direct and readable approach for styling graph elements. ```python ipx.network( G, layout=pos, vertex_labels=True, vertex_size=30, vertex_facecolor="lightblue", vertex_edgecolor="none", vertex_label_color="black", edge_linestyle=linestyle, edge_paralleloffset=0, edge_looptension=3.5, edge_arrow_marker=">", ) ``` -------------------------------- ### get_loopmaxangle Source: https://iplotx.readthedocs.io/en/latest/api/artists.html Gets the maximum angle for loops. ```APIDOC ## get_loopmaxangle() ### Description Get the maximum angle for loops. ### Returns The maximum angle in degrees that a loop can take. If None, the default is 60. ``` -------------------------------- ### Node Labels and Colors Customization Source: https://iplotx.readthedocs.io/en/latest/_sources/gallery/network_science/index.rst.txt Demonstrates how to customize node labels and colors for better graph visualization. ```python import networkx as nx import matplotlib.pyplot as plt # Create a graph G = nx.Graph() G.add_edges_from([(1, 2), (1, 3), (2, 3), (3, 4)]) # Define node labels and colors labels = {1: 'A', 2: 'B', 3: 'C', 4: 'D'} colors = ['red', 'blue', 'green', 'purple'] # Get positions for drawing pos = nx.spring_layout(G) # Draw the graph with custom labels and colors nx.draw(G, pos, labels=labels, node_color=colors, with_labels=True, node_size=500, font_size=10, edge_color='gray') plt.title("Node Labels and Colors") plt.show() ``` -------------------------------- ### get_curved Source: https://iplotx.readthedocs.io/en/latest/api/artists.html Gets whether the edges are curved or not. ```APIDOC ## get_curved() ### Description Get whether the edges are curved or not. ### Returns A bool that is True if the edges are curved, False if they are straight. ``` -------------------------------- ### get_datalims_children Source: https://iplotx.readthedocs.io/en/latest/api/artists.html Gets the data limits of the children of this artist. ```APIDOC ## get_datalims_children ### Description Get the data limits of the children of this artist. ### Method `get_datalims_children(_transData =None_) -> Sequence[Bbox]` ### Parameters #### transData - **transData**: Optional transform data. ### Returns - A sequence of Bbox objects representing the data limits of the children. ``` -------------------------------- ### Displaying Network with Vertex Markers Source: https://iplotx.readthedocs.io/en/latest/gallery/style/plot_vertexmarkers.html This snippet shows how to create a network graph and apply different vertex markers, sizes, and colors. It utilizes igraph for graph creation and iplotx for visualization, setting up a star layout and custom color mapping. ```python import igraph as ig import numpy as np import iplotx as ipx markers = ["o", "s", "^", "v", "<", ">", "d", "e", "p", "h", "8", "*"] n = len(markers) g = ig.Graph( edges=[(0, i + 1) for i in range(n)], directed=False, ) # Create star layout layout = {i + 1: (np.cos(2 * np.pi / n * i), np.sin(2 * np.pi / n * i)) for i in range(n)} layout[0] = (0, 0) # Colors colors = [ "k", "#8dd3c7", "#ffffb3", "#bebada", "#fb8072", "#80b1d3", "#fdb462", "#b3de69", "#fccde5", "#bf5b17", "#666666", "#000000", "#bbbbbb", ] colors = {i: colors[i] for i in range(n + 1)} ipx.network( g, layout=layout, vertex_marker=markers, vertex_size={i: 20 * bool(i) for i in range(n + 1)}, vertex_facecolor=colors, vertex_edgecolor="black", aspect=1, ) ``` -------------------------------- ### get_offset Source: https://iplotx.readthedocs.io/en/latest/api/artists.html Gets the offset for parallel straight edges. ```APIDOC ## get_offset() ### Description Get the offset for parallel straight edges. ### Returns The offset in points for parallel straight edges. If None, the default is 3. ``` -------------------------------- ### Customize Branch Support Label Placement Source: https://iplotx.readthedocs.io/en/latest/_downloads/ab47bbf2156acc6f1b3ebb544a401c2f/plot_support.ipynb Demonstrates how to adjust the placement and alignment of branch support labels using margin and alignment parameters. Two subplots show different configurations. ```python fig, axs = plt.subplots(2, 1, figsize=(5, 9)) art = ipx.tree( tree, ax=axs[0], leaf_labels=True, style="cogent3", show_support=True, vertex_label_hmargin=-1, vertex_label_vmargin=5, vertex_label_horizontalalignment="right", title="Move top left, right-aligned", ) art = ipx.tree( tree, ax=axs[1], leaf_labels=True, style="cogent3", show_support=True, vertex_label_hmargin=+1, vertex_label_vmargin=0, vertex_label_horizontalalignment="left", title="Move center right, left-aligned", ) ``` -------------------------------- ### VertexCollection.axes Source: https://iplotx.readthedocs.io/en/latest/api/artists.html Gets the Axes instance the artist resides in. ```APIDOC ## axes ### Description The ~.axes.Axes instance the artist resides in, or _None_. ### Property axes ``` -------------------------------- ### Force Leaf Edges and Customize Appearance Source: https://iplotx.readthedocs.io/en/latest/_downloads/1282670c6ec70d6181c0dc748cc2773e/plot_leafedges.ipynb This example demonstrates how to force the plotting of leaf edges even without leaf labels, and how to customize their color, linewidth, and linestyle. Use this for explicit visual emphasis on leaf connections. ```python ipx.plotting.tree( tree, leaf_deep=True, leafedge_color="tomato", leafedge_linewidth=2, leafedge_linestyle="-.", ) ``` -------------------------------- ### get_sizes_dpi Source: https://iplotx.readthedocs.io/en/latest/api/artists.html Get arrow sizes (max of width and height) scaled by dpi. ```APIDOC ## get_sizes_dpi ### Description Get arrow sizes (max of width and height) scaled by dpi. ### Method GET (or equivalent for object method call) ### Endpoint N/A (Object method) ### Parameters None ``` -------------------------------- ### Styling Groups with iplotx Source: https://iplotx.readthedocs.io/en/latest/gallery/basic/plot_grouping.html Style groups by specifying colors, line widths, and padding. This example demonstrates how to customize the appearance of group hulls, including face color, edge color, line width, and vertex padding. ```python ipx.network( network=g, layout="circle", grouping={ "singleton": {0}, "doublet": {1, 2}, "multiplet": {3, 4, 5, 6, 7}, }, vertex_size=18, vertex_labels=True, vertex_label_color="white", grouping_facecolor=["purple", "deeppink", "tomato"], grouping_edgecolor="black", grouping_linewidth=2, grouping_vertexpadding=21, network_zorder=2, grouping_zorder=1, ) plt.gca().set_aspect(1.0) ``` -------------------------------- ### get_sizes Source: https://iplotx.readthedocs.io/en/latest/api/artists.html Get arrow sizes (max of width and height), not scaled by dpi. ```APIDOC ## get_sizes ### Description Get arrow sizes (max of width and height), not scaled by dpi. ### Method GET (or equivalent for object method call) ### Endpoint N/A (Object method) ### Parameters None ``` -------------------------------- ### Graph Creation and Shortest Path Calculation Source: https://iplotx.readthedocs.io/en/latest/gallery/network_science/plot_shortest_path.html This snippet sets up a graph with nodes and weighted edges, then calculates the shortest path between two specified nodes using the 'weight' attribute. It also prepares edge attributes for visualization, coloring the shortest path edges red. ```python import networkx as nx import matplotlib.pyplot as plt import iplotx as ipx G = nx.Graph() G.add_nodes_from(["A", "B", "C", "D", "E", "F", "G", "H"]) G.add_edge("A", "B", weight=4) G.add_edge("A", "H", weight=8) G.add_edge("B", "C", weight=8) G.add_edge("B", "H", weight=11) G.add_edge("C", "D", weight=7) G.add_edge("C", "F", weight=4) G.add_edge("C", "I", weight=2) G.add_edge("D", "E", weight=9) G.add_edge("D", "F", weight=14) G.add_edge("E", "F", weight=10) G.add_edge("F", "G", weight=2) G.add_edge("G", "H", weight=1) G.add_edge("G", "I", weight=6) G.add_edge("H", "I", weight=7) # Find the shortest path from node A to node E path = nx.shortest_path(G, "A", "E", weight="weight") # Create a list of edges in the shortest path path_edges = list(zip(path, path[1:])) x.set_node_attributes(G, nx.spring_layout(G, seed=37), "pos") x.set_edge_attributes( G, { (u, v): { "color": ( "red" if (u, v) in path_edges or tuple(reversed((u, v))) in path_edges else "black" ), "label": d["weight"], } for u, v, d in G.edges(data=True) }, ) fig, ax = plt.subplots() ipx.plot( G, ax=ax, layout="pos", vertex_labels=True, edge_labels=True, ) ``` -------------------------------- ### Visualize a simple tree with SimpleTree Source: https://iplotx.readthedocs.io/en/latest/gallery/zero_dependency/plot_simpletreedataprovider.html Use this snippet to visualize a tree structure using iplotx's SimpleTree. This is useful for projects that do not require external tree libraries or for educational demonstrations. Ensure iplotx is installed. ```python import iplotx as ipx tree = { "children": ( {}, { "children": ( { "children": ( {"branch_length": 1.5}, {} ) }, { "children": ( {}, {} ) } ) } ) } # Convert to our simple tree data structure tree = ipx.ingest.providers.tree.simple.SimpleTree.from_dict(tree) ipx.tree( tree, ) ``` -------------------------------- ### get_size Source: https://iplotx.readthedocs.io/en/latest/api/artists.html Get arrow sizes (max of width and height), not scaled by dpi. ```APIDOC ## get_size ### Description Get arrow sizes (max of width and height), not scaled by dpi. ### Method GET (or equivalent for object method call) ### Endpoint N/A (Object method) ### Parameters None ``` -------------------------------- ### get_offset_transform Source: https://iplotx.readthedocs.io/en/latest/api/artists.html Get offset transform for the edge arrows. This sets the tip of each arrow. ```APIDOC ## get_offset_transform ### Description Get offset transform for the edge arrows. This sets the tip of each arrow. ### Method GET (or equivalent for object method call) ### Endpoint N/A (Object method) ### Parameters None ``` -------------------------------- ### Plotting an Undirected Ring Graph with Various Styles Source: https://iplotx.readthedocs.io/en/latest/gallery/style/plot_multistyle.html This snippet plots an undirected ring graph using the same list of iplotx styles as the previous example. It applies each style to a separate subplot, allowing for a direct comparison of how styles affect undirected graphs. Similar to the directed graph example, vertex labels and margins are conditionally applied. ```python g = ig.Graph.Ring(9, directed=False) fig, axs = plt.subplots(5, 2, figsize=(7.5, 20)) for style, ax in zip(styles, axs.ravel()): ipx.plot( g, ax=ax, layout="circle", style=style, vertex_labels=style in ("default", "hollow", "unicorn", "networkx", "igraph"), title=style, margins=0.1 if style == "unicorn" else 0, ) ``` -------------------------------- ### Create a Style Context in iplotx Source: https://iplotx.readthedocs.io/en/latest/api/style.html Use this function to create a style context for iplotx. It accepts a single style specification or a list of specifications, which are applied in order. Additional keyword arguments can override styles at the end. ```python iplotx.style.context(_style : str | dict[str, Any] | Sequence[str | dict[str, Any]] | Iterable[str | dict[str, Any]] | None = None_, _** kwargs_) ```