<jupyter_start><jupyter_text>Make graphs in Python with NetworkX **TODO*** https://networkx.github.io/index.html* https://github.com/networkx/notebooks* https://networkx.readthedocs.io/en/stable/examples/drawing/labels_and_colors.html<jupyter_code>%matplotlib inline

import networkx as nx
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Example 1<jupyter_code>g = nx.Graph()

g.add_node("Foo")
g.add_edge("Foo", 1)
g.add_edge(1, 2)
g.add_edge(1, 3)
g.add_edge(1, 4)
g.add_edge(3, 4)
list(g.nodes())
list(g.edges())
pos = nx.spring_layout(g)

nx.draw_networkx(g, pos, node_color='#ffaaff', node_size=800)

#plt.savefig("ex1.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Example 2<jupyter_code>g = nx.Graph()
g.add_edges_from([(0, 1), (0, 2), (0, 3), (1, 2)])
list(g.nodes())
list(g.edges())
pos = nx.spring_layout(g)

nx.draw_networkx_nodes(g, pos, node_size=20)
nx.draw_networkx_edges(g, pos, alpha=0.4)

#plt.savefig("ex2.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Random graph<jupyter_code>g = nx.gnm_random_graph(10, 20)
list(g.nodes())
list(g.edges())
pos = nx.spring_layout(g)

nx.draw_networkx_nodes(g, pos, node_size=20)
nx.draw_networkx_edges(g, pos, alpha=0.4)
nx.draw_networkx_labels(g, pos, alpha=0.4)

#plt.savefig("random_graph1.png")
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18040089086859687, 'fraction_numerical': 0.028953229398663696, 'mean_word_length': 7.696774193548387, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 3, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '610597', 'license': 'MIT', 'n_tokens_mistral': 627, 'n_tokens_neox': 600, 'n_words': 82, 'path': 'nb_dev_python/python_networkx_en.ipynb', 'repo_name': 'jdhp-docs/python-notebooks', 'size': '1347'}