Ever wondered what it takes to visualize a sprawling city like Chicago on your screen — using nothing but code? As someone passionate about data, maps, and automation, I set out to map Chicago using Python. This post breaks down how I did it, tools I used, and how you can replicate this for any city.
Whether you're a Python developer, a data analyst, or just a curious explorer — this is for you.
Tools & Libraries I Used
To keep things open-source and efficient, I used the following Python libraries:
- geopandas – for spatial data manipulation
- matplotlib – for visualizing the map
- contextily – for adding background tiles
- osmnx – to download and plot street networks from OpenStreetMap
- shapely – for geometric operations
You can install all dependencies using pip:
pip install geopandas matplotlib contextily osmnx shapely
Step-by-Step: Mapping Chicago
1. Get the Boundary of Chicago
Using OSMnx, I first downloaded the polygon boundary of Chicago.
import osmnx as ox
# Fetch the city boundary
city = ox.geocode_to_gdf("Chicago, Illinois, USA")
city.plot()
This gave me an accurate geographic outline of the city — ready to be layered with roads, buildings, and other data.
2. Download Chicago’s Street Network
I wanted to see the complete street grid, so I pulled data for all drivable roads.
G = ox.graph_from_place("Chicago, Illinois, USA", network_type="drive")
ox.plot_graph(ox.project_graph(G))
Want bike paths, footways, or public transport? Just change network_type.
3. Convert to GeoDataFrame
To perform analysis or plot on layers, I converted the network to a GeoDataFrame.
gdf_nodes, gdf_edges = ox.graph_to_gdfs(G)
Now, I had each road as a line geometry I could filter, color, or export.
4. Add a Basemap for Context
To make it visually appealing, I added a tile basemap using contextily.
import contextily as ctx
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(12,12))
gdf_edges.plot(ax=ax, linewidth=0.5, color="black")
ctx.add_basemap(ax, source=ctx.providers.CartoDB.Positron, crs=gdf_edges.crs.to_string())
plt.title("Street Network of Chicago", fontsize=15)
plt.axis('off')
plt.show()
This resulted in a beautiful, modern-looking map with the road layout of Chicago overlaid on real map tiles.
**Bonus: **Mapping Points of Interest
I went a step further and fetched places like hospitals, schools, and parks:
tags = {'amenity': ['school', 'hospital', 'library']}
pois = ox.features_from_place("Chicago, Illinois, USA", tags)
pois.plot(figsize=(10,10), color='green', markersize=5)
This allowed me to visualize where critical services are concentrated or missing.
Exporting as an Image or GeoJSON
You can save your map as a high-res PNG or even a GeoJSON for use in web maps:
gdf_edges.to_file("chicago_streets.geojson", driver="GeoJSON")
What I Learned
Mapping Chicago taught me:
- OpenStreetMap + Python = Unlimited Potential
- Python makes geospatial data accessible even without a GIS degree
- Visualizing urban data helps uncover patterns you can’t see on spreadsheets
Want to Map Your City?
You can replace "Chicago, Illinois, USA" with any city name. Try:
"New York City, New York, USA"
"Los Angeles, California, USA"
"Delhi, India"
This method is universal, free, and incredibly fun.
Final Thoughts
Mapping the whole of Chicago using Python wasn’t just a technical challenge — it was an eye-opener into how accessible geographic data is today. With just a few lines of Python, you can map, analyze, and visualize entire cities.
I plan to explore more — traffic flow, zoning data, green space distribution — and if you're into urban data, you should too.
Feel free to fork the code, modify it, and build your own custom city maps! Looking for a Top SEO company in chicago for small scale business? Check out Nubiz Solutions.
Top comments (0)