Note: This post was originally published by Luis Natera on his personal blog. It has been republished here as part of TYN Studio's content.
I decided to do an exercise to look for communities in a street network and plot them using a custom color palette. The goal was to see how street networks naturally cluster together and visualize those clusters in a meaningful way.
Data Collection
Using OSMnx, I downloaded Guadalajara's street network and projected it into an appropriate coordinate system for visualization. This gives us a graph representation where intersections are nodes and streets are edges.
Community Detection Algorithm
The project employs Louvain Modularity, a method specifically designed for undirected graphs. Since street networks are typically represented as directed graphs (streets have direction), I created a function that converts directed graphs to undirected format while preserving edge weights.
The Louvain method is particularly good at finding communities in large networks because it optimizes for modularity—a measure of how well the network divides into distinct groups.
Color Palette Design
Inspired by architect Luis Barragán's architectural color philosophy, I developed a 28-color custom palette drawn from the architect's buildings. Barragán is famous for his bold use of color in Mexican architecture, and these colors felt perfect for representing a Mexican city.

I implemented the palette through matplotlib's ListedColormap, allowing me to use these architectural colors in the network visualization.
Visualization
The final visualization uses OSMnx's plotting functionality with a black background, white edges for streets, and community-colored nodes (8.5-point size). Each color represents a different community detected by the algorithm.

The result shows how different parts of the city naturally group together based on their connectivity patterns. You can see distinct neighborhoods emerging from the pure network structure, which often correspond to actual geographic and social boundaries in the city.
Code available on GitHub: Community-Detection