← Back to Skills Marketplace
owenciantar

Graph Analysis

by Owen Ciantar · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ Security Clean
176
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install graph-analysis
Description
Analyze graphs and networks using Python NetworkX — centrality, shortest paths, community detection, and visualization.
README (SKILL.md)

Graph Analysis Skill

Analyze graphs and networks using Python and NetworkX. Supports building graphs from data, running graph algorithms, and generating visualizations.

Setup

Before first use, install dependencies:

pip install networkx matplotlib numpy --break-system-packages

Capabilities

1. Build a Graph

Create graphs from edge lists, adjacency matrices, CSV files, or JSON data.

From an edge list (CSV or inline):

import networkx as nx

# From a CSV file with columns: source, target, weight (optional)
import csv
G = nx.Graph()
with open("edges.csv") as f:
    reader = csv.DictReader(f)
    for row in reader:
        weight = float(row.get("weight", 1.0))
        G.add_edge(row["source"], row["target"], weight=weight)

From inline data:

import networkx as nx
G = nx.Graph()
G.add_edges_from([("A", "B"), ("B", "C"), ("A", "C"), ("C", "D")])

Directed graph:

G = nx.DiGraph()
G.add_edges_from([("A", "B"), ("B", "C")])

2. Graph Metrics

Run these to answer questions about graph structure:

import networkx as nx

# Basic stats
print(f"Nodes: {G.number_of_nodes()}")
print(f"Edges: {G.number_of_edges()}")
print(f"Density: {nx.density(G):.4f}")
print(f"Connected: {nx.is_connected(G)}")

# Centrality measures
degree_cent = nx.degree_centrality(G)
betweenness = nx.betweenness_centrality(G)
closeness = nx.closeness_centrality(G)
pagerank = nx.pagerank(G)

# Find most important nodes
top_by_degree = sorted(degree_cent.items(), key=lambda x: x[1], reverse=True)[:10]
top_by_betweenness = sorted(betweenness.items(), key=lambda x: x[1], reverse=True)[:10]
top_by_pagerank = sorted(pagerank.items(), key=lambda x: x[1], reverse=True)[:10]

print("Top nodes by degree centrality:", top_by_degree)
print("Top nodes by betweenness:", top_by_betweenness)
print("Top nodes by PageRank:", top_by_pagerank)

3. Shortest Paths

# Shortest path between two nodes
path = nx.shortest_path(G, source="A", target="D")
length = nx.shortest_path_length(G, source="A", target="D")
print(f"Path: {' -> '.join(path)} (length: {length})")

# Weighted shortest path
path_w = nx.shortest_path(G, source="A", target="D", weight="weight")

# All pairs shortest path lengths
all_lengths = dict(nx.all_pairs_shortest_path_length(G))

4. Community Detection

from networkx.algorithms.community import greedy_modularity_communities, louvain_communities

# Greedy modularity
communities_greedy = list(greedy_modularity_communities(G))
print(f"Found {len(communities_greedy)} communities (greedy)")

# Louvain (better for large graphs)
communities_louvain = list(louvain_communities(G))
print(f"Found {len(communities_louvain)} communities (Louvain)")

# Print community membership
for i, comm in enumerate(communities_louvain):
    print(f"  Community {i}: {sorted(comm)}")

5. Visualization

Save graph visualizations as PNG images:

import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import networkx as nx

fig, ax = plt.subplots(figsize=(12, 8))

# Layout options: spring_layout, circular_layout, kamada_kawai_layout, shell_layout
pos = nx.spring_layout(G, seed=42)

# Size nodes by degree
node_sizes = [300 * G.degree(n) for n in G.nodes()]

# Color nodes by community (if communities were computed)
nx.draw(
    G, pos, ax=ax,
    with_labels=True,
    node_size=node_sizes,
    node_color="steelblue",
    edge_color="#cccccc",
    font_size=8,
    font_weight="bold",
    width=0.8,
)
ax.set_title("Graph Visualization")
plt.tight_layout()
plt.savefig("graph.png", dpi=150)
plt.close()
print("Saved graph.png")

Color by community:

import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import networkx as nx
from networkx.algorithms.community import louvain_communities

communities = list(louvain_communities(G))
color_map = {}
for i, comm in enumerate(communities):
    for node in comm:
        color_map[node] = i

node_colors = [color_map[n] for n in G.nodes()]
pos = nx.spring_layout(G, seed=42)

fig, ax = plt.subplots(figsize=(12, 8))
nx.draw(
    G, pos, ax=ax,
    with_labels=True,
    node_color=node_colors,
    cmap=plt.cm.Set3,
    node_size=500,
    edge_color="#cccccc",
    font_size=8,
)
ax.set_title("Communities")
plt.tight_layout()
plt.savefig("communities.png", dpi=150)
plt.close()
print("Saved communities.png")

6. Graph Generators (for testing or simulation)

import networkx as nx

# Common test graphs
G = nx.karate_club_graph()          # Classic social network (34 nodes)
G = nx.barabasi_albert_graph(100, 3) # Scale-free network
G = nx.erdos_renyi_graph(50, 0.1)    # Random graph
G = nx.watts_strogatz_graph(30, 4, 0.3)  # Small-world network

When to Use This Skill

Use this skill when the user asks to:

  • Analyze relationships, connections, or networks in data
  • Find important/central/influential nodes in a network
  • Detect communities or clusters in a graph
  • Find shortest paths between entities
  • Visualize a network or relationship diagram
  • Build a graph from CSV, JSON, or other structured data
  • Run graph algorithms (PageRank, centrality, clustering coefficient, etc.)

Notes

  • For large graphs (>10,000 nodes), prefer louvain_communities over greedy_modularity_communities
  • Always use matplotlib.use("Agg") before importing pyplot (no display server)
  • Save visualizations as PNG files and show them to the user
  • When reading user data, infer source/target columns from context — common patterns include: from/to, source/target, node1/node2, parent/child
Usage Guidance
This skill is essentially a how-to for doing graph analysis with NetworkX and appears coherent. Before installing/running: 1) run the pip installs inside a virtualenv or conda environment instead of using `--break-system-packages`; 2) verify the louvain/community function you need is available in your NetworkX version (some setups require an extra community package); 3) be mindful that the skill's examples read user CSV/JSON files and write PNGs — only provide data you want analyzed or shared; 4) the skill metadata declares files (scripts/*) that are not present in the package — that mismatch is benign but worth confirming the repo/source you obtained; 5) if you will run this in an environment with sensitive system data, sandbox the execution and review any concrete code before granting file access.
Capability Analysis
Type: OpenClaw Skill Name: graph-analysis Version: 1.0.0 The graph-analysis skill bundle is a legitimate tool for network analysis using the standard Python library NetworkX. The SKILL.md file contains well-documented, standard code snippets for graph construction, metric calculation, community detection, and visualization using matplotlib, with no evidence of malicious intent, data exfiltration, or prompt injection.
Capability Assessment
Purpose & Capability
Name/description (graph analysis with NetworkX) lines up with the instructions: building graphs, metrics, paths, community detection, visualization. Required tools (python3, pip) in the metadata are reasonable for this purpose.
Instruction Scope
Instructions tell the agent to read user-provided CSV/JSON files and save PNGs — this is expected for a data-analysis skill. The SKILL.md does not instruct reading system credentials or unrelated paths. It does recommend installing packages and inferring source/target columns from user data, so users should be aware the agent will access files the user supplies.
Install Mechanism
This is an instruction-only skill (no install spec), but the README tells operators to run `pip install networkx matplotlib numpy --break-system-packages`. Installing from PyPI is normal for Python tools, but `--break-system-packages` can alter system Python environments and is risky — prefer using a virtual environment. No downloads from arbitrary URLs or archive extraction are present.
Credentials
No environment variables, credentials, or config paths are requested. The skill does not ask for unrelated secrets or broad access tokens.
Persistence & Privilege
Skill is not forced always-on and does not request elevated agent-level persistence or modify other skills. Autonomous invocation is allowed (platform default) but not combined with any broad privileges here.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install graph-analysis
  3. After installation, invoke the skill by name or use /graph-analysis
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
Initial release of the graph-analysis skill. - Analyze graphs and networks using Python NetworkX: centrality, shortest paths, community detection, and visualization. - Supports building graphs from edge lists, CSV/JSON data, and test graph generators. - Provides metrics (degree, betweenness, closeness, PageRank), pathfinding, and community detection. - Enables saving network visualizations as PNG images, including community coloring. - Includes setup and usage instructions for interactive data analysis.
Metadata
Slug graph-analysis
Version 1.0.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is Graph Analysis?

Analyze graphs and networks using Python NetworkX — centrality, shortest paths, community detection, and visualization. It is an AI Agent Skill for Claude Code / OpenClaw, with 176 downloads so far.

How do I install Graph Analysis?

Run "/install graph-analysis" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is Graph Analysis free?

Yes, Graph Analysis is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does Graph Analysis support?

Graph Analysis is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created Graph Analysis?

It is built and maintained by Owen Ciantar (@owenciantar); the current version is v1.0.0.

💬 Comments