-1

I am creating a graph_from_point using osmnx. I want to save that graph to a PNG image, but created a supplementary file giving me the lat/lng coords of nodes along with their PIXEL coord in the saved PNG file.

This tutorial : https://matplotlib.org/users/transforms_tutorial.html suggests should be able to 'transform from your data to your display coordinate system' (I'm aware there is a potential display vs save DPI issue) which appears to be what I need, but if I try and use transData, I get the error below.

G = ox.graph_from_point(map_query, distance=map_distance, network_type=map_network_type, simplify=True)
list(G.nodes.data())
# {'y': 51.5025637, 'x': 0.1111431, 'osmid': 95944704}
print type(G.transData)
AttributeError: 'MultiDiGraph' object has no attribute 'transData' 

Is this the correct approach but I am referencing the wrong object? Or is this not valid? I am unsure of the relationship between networkx and matplotlib. My ultimate goal would be to have :

{'y': 51.5025637, 'x': 0.1111431, 'osmid': 95944704, 'pixel' : (23, 467)}

With pixel being the reference to the saved file created by:

ox.plot_graph(G, save=True, file_format='png', filename='example', fig_height=my_fig_height, dpi=my_dpi)
user1676300
  • 135
  • 7

1 Answers1

0

I am unsure of the relationship between networkx and matplotlib.

There is no inherent relationship between OSMnx/NetworkX and matplotlib. NetworkX MultiDiGraph objects do not have matplotlib axis attributes, such as transData. I would suggest reading the OSMnx documentation. OSMnx can plot a graph via matplotlib, and return a figure and axis to you. You can then manipulate and work with this axis as you see fit.

gboeing
  • 5,691
  • 2
  • 15
  • 41