import xml.etree.ElementTree as ET
import matplotlib.pyplot as plt

tree = ET.parse('map.osm')
root = tree.getroot()

nodes = [child for child in root if child.tag == 'node']
V = {node.attrib['id']: (float(node.attrib['lon']), float(node.attrib['lat'])) for node in nodes}

ways = [child for child in root if child.tag == 'way']

edges = []
for way in ways:
    for child in way:
        if child.tag == 'tag' and 'k' in child.attrib and child.attrib['k'] == 'highway':
            points = [child.attrib['ref'] for child in way if child.tag == 'nd']
            for p, q in zip(points, points[1:]):
                edges.append((p, q))
        
data = []
for p, q in edges:
    xs, ys = zip(V[p], V[q])
    data.extend((xs, ys, '-'))

plt.plot(*data, color='k')  # edges       
plt.show()
