<jupyter_start><jupyter_text>Street network bearingsCalculate street network bearings and visualize the spatial orientation of a street network.  - [Overview of OSMnx](http://geoffboeing.com/2016/11/osmnx-python-street-networks/)  - [GitHub repo](https://github.com/gboeing/osmnx)  - [Examples, demos, tutorials](https://github.com/gboeing/osmnx-examples)  - [Documentation](https://osmnx.readthedocs.io/en/stable/)<jupyter_code>import osmnx as ox, pandas as pd, matplotlib.pyplot as plt
%matplotlib inline
ox.config(log_console=True, use_cache=True)<jupyter_output><empty_output><jupyter_text>First, look at a non-grid street networkMoraga, California is a hilly suburb with winding loops and cul-de-sacs. We can see this lack of consistent orientation in its histogram of edge bearings.<jupyter_code>G = ox.graph_from_place('Moraga, California', network_type='drive')
fig, ax = ox.plot_graph(ox.project_graph(G), node_size=0)
# calculate edge bearings and visualize their frequency
G = ox.add_edge_bearings(G)
bearings = pd.Series([data['bearing'] for u, v, k, data in G.edges(keys=True, data=True)])
ax = bearings.hist(bins=30, zorder=2, alpha=0.8)
xlim = ax.set_xlim(0, 360)
ax.set_title('Moraga street network edge bearings')
plt.show()
# polar plot
import numpy as np
bin = 30
count, division = np.histogram(bearings, bins=[ang*360/bin for ang in range(0,bin+1)])
division = division[0:-1]
width =  2 * np.pi/bin
ax = plt.subplot(111, projection='polar')
bars = ax.bar(division * np.pi/180 - width * 0.5 , count, width=width, bottom=0.0)
plt.show()<jupyter_output><empty_output><jupyter_text>Now look at a gridded street networkSanta Monica has an orthogonal grid characterized by four-way intersections. We can see this clear orientation in its histogram of edge bearings.<jupyter_code>G = ox.graph_from_place('Santa Monica, California', network_type='drive')
fig, ax = ox.plot_graph(ox.project_graph(G), node_size=0)
# calculate edge bearings and visualize their frequency
G = ox.add_edge_bearings(G)
bearings = pd.Series([data['bearing'] for u, v, k, data in G.edges(keys=True, data=True)])
ax = bearings.hist(bins=30, zorder=2, alpha=0.8)
ax.set_xlim(0, 360)
ax.set_title('Santa Monica street network edge bearings')
plt.show()
# polar plot
bin = 30
count, division = np.histogram(bearings, bins=[ang*360/bin for ang in range(0,bin+1)])
division = division[0:-1]
width =  2 * np.pi/bin
ax = plt.subplot(111, projection='polar')
bars = ax.bar(division * np.pi/180 - width * 0.5 , count, width=width, bottom=20.0)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13348946135831383, 'fraction_numerical': 0.02615144418423107, 'mean_word_length': 5.871313672922252, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '308528', 'license': 'MIT', 'n_tokens_mistral': 961, 'n_tokens_neox': 874, 'n_words': 235, 'path': 'notebooks/15-calculate-visualize-edge-bearings.ipynb', 'repo_name': 'Gbachant/osmnx-examples', 'size': '2562'}