<jupyter_start><jupyter_text>Specifying Node Positions and Plotting via NetworkX We specify node positions and used them to plot a network with NetworkX.  1. Toy example While it is usually sufficient to pass edge data to setup a graph, one may specify further attributes, such as their coordinates in a 2D plane for plotting. This can be simply done by further passing node data to the network constructor:<jupyter_code>import paminco
import numpy as np

edge_data = np.array([
    ["A", "B"],
    ["A", "C"],
    ["B", "C"],
    ["B", "D"],
    ["C", "D"],
])
labels = ["A", "B", "C", "D"]
xy = [(0, 0), (0, 3), (3, 3), (3, 0)]
node_data = (labels, xy)
graph = paminco.Network(edge_data, node_data)<jupyter_output><empty_output><jupyter_text>We can verify if the node coordinates are correctly specified:<jupyter_code>graph.nodes.to_df()<jupyter_output><empty_output><jupyter_text>We can use the Python package [NetworkX](https://networkx.org/) for basic plotting:<jupyter_code>import matplotlib.pyplot as plt
import networkx as nx

import matplotlib.pyplot as plt
import networkx as nx

# Retrive position dict (label -> (x, y))
pos = graph.get_node_pos()

# Set fictious flow and get as edgelist
flow = np.array([1, 2, 3, 4, 5])  # E.g., flow on A -> B = 1, ..., C -> D = 5
flow = graph.get_flow_df(flow)

# Make nx.DiGraph from edgelist
G = nx.from_pandas_edgelist(
    flow,
    edge_attr=["flow"],
    create_using=nx.DiGraph(),
)

# Plot, nodes, edges and labels
plt.figure(figsize=(8, 5))
nx.draw_networkx_nodes(G, pos, node_color="lightgrey")
nx.draw_networkx_edges(
    G,
    pos, 
    width=flow.flow,
)
_ = nx.draw_networkx_labels(G, pos)<jupyter_output><empty_output><jupyter_text>2. SiouxFalls First, we load the SiouxFalls network with its specified node positions:<jupyter_code>sioux = paminco.load_sioux()
sioux.nodes.to_df().head()<jupyter_output><empty_output><jupyter_text>We can use [NetworkX](https://networkx.org/) to plot SiouxFalls. Similar to the toy example, we proceed by retrieving an edgelist from our network structure and a position dict.<jupyter_code># Retrive position dict (label -> (x, y))
pos = sioux.get_node_pos()
edge_list = sioux.get_flow_df(1)

# Make nx.DiGraph from edgelist
G = nx.from_pandas_edgelist(
    edge_list,
    edge_attr=["flow"],
    create_using=nx.DiGraph(),
)

# Plot, nodes, edges and labels
plt.figure(figsize=(10, 14))
nx.draw_networkx_nodes(G, pos, node_color="lightgrey")
nx.draw_networkx_edges(
    G,
    pos, 
    width=edge_list.flow,#
    connectionstyle="arc3, rad=0.1",
)
_ = nx.draw_networkx_labels(G, pos)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13098429720413635, 'fraction_numerical': 0.010723860589812333, 'mean_word_length': 4.8961625282167045, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '141995', 'license': 'MIT', 'n_tokens_mistral': 973, 'n_tokens_neox': 941, 'n_words': 268, 'path': 'docs/source/user_guide/network_setup/howto_plot_network.ipynb', 'repo_name': 'paminco/paminco', 'size': '2611'}