Reputation: 75
I am currently trying to plot lat long points with connected edges from a map api to a summarizing graph. I'm currently using plotly to do this from python, but my issue is that the horizontal axis 'zooms' or stretches, as documented here resulting in something like this:
Can anyone recommend a 2D vector plotting library in js or python to accomplish this without stretching?
Upvotes: 0
Views: 347
Reputation: 31226
import osmnx as ox
import plotly.express as px
import numpy as np
# get some edges
gdf = ox.geocode_to_gdf('Topsham, Devon')
G = ox.graph_from_polygon(gdf.loc[0,"geometry"], network_type='drive')
gdf_nodes, gdf_edges = ox.graph_to_gdfs(G)
# plotly lines are arrays of points with each line separated by None
px.line(
x=np.concatenate(
gdf_edges["geometry"].apply(lambda g: [c[1] for c in g.coords] + [None]).values
),
y=np.concatenate(
gdf_edges["geometry"].apply(lambda g: [c[0] for c in g.coords] + [None]).values
),
)
px.line_mapbox(
lat=np.concatenate(
gdf_edges["geometry"].apply(lambda g: [c[1] for c in g.coords] + [None]).values
),
lon=np.concatenate(
gdf_edges["geometry"].apply(lambda g: [c[0] for c in g.coords] + [None]).values
),
).update_layout(mapbox={"style":"carto-positron", "zoom":13})
gdf_edges.explore()
Upvotes: 1