networkx

Create, analyze, and visualize complex networks and graphs in Python.

Updated Aug 12, 2026
One-click install
npx skills add https://github.com/littlt-momo-c-yfc/skills --skill networkx-littlt-momo-c-yfc
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: networkx
Source: https://github.com/littlt-momo-c-yfc/skills/tree/main/skills/scientific-toolkit-skill/references/scientific-skills/networkx
Command: npx skills add https://github.com/littlt-momo-c-yfc/skills --skill networkx-littlt-momo-c-yfc

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires networkx, matplotlib, pandas, numpy, scipy, and includes references (resource) components.

What problem does it solve? Working with network and graph data—social networks, citation networks, biological interactions, transportation systems—requires specialized algorithms for paths, centrality, communities, and visualization that are tedious to implement from scratch. This Skill provides comprehensive guidance for using NetworkX to handle the full graph analysis workflow in Python. ## Core Features & Use Cases - Graph Construction & I/O: Build directed, undirected, and multi-edge graphs from edge lists, GraphML, GML, JSON, CSV, Pandas DataFrames, NumPy arrays, and SciPy sparse matrices. - Graph Algorithms: Compute shortest paths, centrality measures (degree, betweenness, PageRank), clustering coefficients, community detection, maximum flow, and spanning trees. - Synthetic Network Generation: Generate random, scale-free, small-world, lattice, and stochastic block model networks with reproducible seeds. - Visualization: Render networks with matplotlib layouts (spring, circular, spectral, Kamada-Kawai), customize node/edge appearance, and export publication-quality figures. - Use Case: Given a CSV of protein-protein interactions, load it as a graph, detect functional communities via modularity maximization, rank proteins by betweenness centrality, and export a colored network figure for a paper. ## Quick Start Use the networkx skill to load my edge list CSV, compute PageRank centrality for all nodes, and draw the network with a spring layout.

Frequently Asked Questions about networkx

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I find the shortest path between two nodes in NetworkX?

Use nx.shortest_path(G, source, target) to get the path and nx.shortest_path_length() for its length. For weighted graphs, pass weight='weight' to use Dijkstra's algorithm with edge weights.

How do I detect communities in a network with Python?

Import networkx.algorithms.community and call greedy_modularity_communities(G) for modularity-based detection, or label_propagation_communities(G) for a faster approach. You can measure partition quality with community.modularity(G, communities).

What file formats does NetworkX support for reading graphs?

NetworkX reads edge lists, adjacency lists, GraphML, GML, GEXF, Pajek, JSON node-link data, Pandas DataFrames, NumPy arrays, and SciPy sparse matrices. GraphML and GML preserve node and edge attributes best.

Does NetworkX work well for very large graphs?

NetworkX loads entire graphs into memory, so very large networks can be slow. Use approximate algorithms like betweenness_centrality with the k sampling parameter, sparse matrix representations, and fast generators like fast_gnp_random_graph.

Why do my NetworkX layouts look different every time?

Force-directed layouts like spring_layout use random initialization. Pass a fixed seed parameter, such as nx.spring_layout(G, seed=42), to get reproducible node positions across runs.