Example: Words Graph

Example: Words Graph

Did you like our graph network where we relate the concepts and tools?

Lets see now!.

Requirements

  • Python
  • Dependencies on a requirements.txt
jupyterlab==4.4.1
matplotlib==3.10.1
networkx==3.4.2

Setup

cd <your path>
# Create a virtual env
python -m venv venv

# Activate the virtual env
source venv/bin/activate

# Install the dependencies
pip install -r requirements.txt

# Start the JupyterLab server
jupyter lab
# You will see the JupyterLab UI on your default web browser

Basic example

  • Create a new Notebook on JupyterLab.
  • cell 1
# Import the installed libs
import networkx as nx
import matplotlib.pyplot as plt
  • cell 2, creating nodes and edges
# Create the graph
G = nx.Graph()

# Add the nodes
G.add_node("Node 1")
G.add_node("Node 2")
G.add_node("Node 3")
G.add_node("Node 4")

# Add the edges
G.add_edge("Node 1", "Node 2")
G.add_edge("Node 1", "Node 3")
G.add_edge("Node 3", "Node 2")
G.add_edge("Node 3", "Node 4")
  • cell 3, graph visualization
# Build the visualization
fig1 = plt.figure(figsize=(12, 8))
nx.draw(G, with_labels=True)

# Show as image
plt.show()
Last updated on