Skip to content

Instantly share code, notes, and snippets.

@braunfuss
Last active June 5, 2021 16:47
Show Gist options
  • Save braunfuss/2b3fdb351b43abe40c6275ef9d11b308 to your computer and use it in GitHub Desktop.
Save braunfuss/2b3fdb351b43abe40c6275ef9d11b308 to your computer and use it in GitHub Desktop.
plot_street_orientation_city.py
import matplotlib.pyplot as plt
import numpy as np
import osmnx as ox
'''
Slimmed down example plot of city street network orientations for a single city,
instead of multiple as in the osmnx notebook.
Needs the awesome package osmnx:
https://github.com/gboeing/osmnx
e.g. pip install osmnx
'''
weight_by_length = False
# define the study sites as label : query
place = {
"Hannover": "Hannover, Germany",
}
# create figure and ax
figsize = (5,5)
fig, ax = plt.subplots(1, 1, figsize=figsize, subplot_kw={"projection": "polar"})
# plot each city's polar histogram
for place in sorted(place.keys()):
print(ox.utils.ts(), place)
# get undirected graphs with edge bearing attributes
G = ox.graph_from_place(place, network_type="drive")
Gu = ox.add_edge_bearings(ox.get_undirected(G))
fig, ax = ox.bearing.plot_orientation(Gu, ax=ax, title=place, area=True)
# add figure title and save image
suptitle_font = {
"family": "DejaVu Sans",
"fontsize": 16,
"fontweight": "normal",
"y": 1,
}
fig.suptitle("Street Network Orientation", **suptitle_font)
fig.tight_layout()
fig.subplots_adjust(hspace=0.35)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment