Welcome to the NetworkX Upskilling repository! This repository is dedicated to helping you enhance your skills and understanding of NetworkX, a powerful Python library for the creation, manipulation, and study of complex networks of nodes and edges.
NetworkX is a Python package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks. This repository aims to provide tutorials, examples, and projects to help you get started and advance your expertise with NetworkX.
To get started with NetworkX, you need to have Python installed on your machine. We recommend using Python 3.10 or higher.
You can install NetworkX using pip:
pip install networkx
Additionally, for visualization, you may want to install Matplotlib and other useful libraries:
pip install matplotlib
pip install numpy
Below are a few examples to help you get started with NetworkX:
This example demonstrates how to create a basic graph:
import networkx as nx
import matplotlib.pyplot as plt
# Create an empty graph
G = nx.Graph()
# Add nodes
G.add_node(1)
G.add_nodes_from([2, 3, 4])
# Add edges
G.add_edge(1, 2)
G.add_edges_from([(2, 3), (3, 4), (4, 1)])
# Draw the graph
nx.draw(G, with_labels=True)
plt.show()
This example showcases some common graph algorithms:
import networkx as nx
# Create a graph
G = nx.cycle_graph(4)
# Compute shortest paths
print("Shortest path between nodes 0 and 3:")
print(nx.shortest_path(G, source=0, target=3))
# Compute degree centrality
print("Degree centrality of the graph:")
print(nx.degree_centrality(G))
This example illustrates how to visualize a graph with additional attributes:
import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
G.add_edge(1, 2, weight=4.2)
G.add_edge(2, 3, weight=6.1)
pos = nx.spring_layout(G)
edges = nx.draw_networkx_edges(G, pos, edge_color='black')
nodes = nx.draw_networkx_nodes(G, pos, node_color='red', node_size=500)
labels = nx.draw_networkx_labels(G, pos)
plt.show()
Explore or add sophisticated projects that utilize NetworkX for analyzing various types of real-world networks, such as social networks, transportation networks, and more.
To add your projects, create a folder in the projects
directory and include your code, data, and a brief description.