Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

430
Views
Alternatives to plotly.graph_objects for plotting 2D lines (python or js)

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: enter image description here

Can anyone recommend a 2D vector plotting library in js or python to accomplish this without stretching?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I used the NetworkX and matplotlib.pyplot library.

about 4 years ago · Juan Pablo Isaza Report

0

  • you have been quite abstract defining your data. Hence I used simple to use osmnx which provides simple way to source nodes and edges
  • edges will be LineString, plotly wants a list of lat and lon, hence extraction of co-ordinates and flattening
  • have demonstrated
    1. line trace, clearly this is stretched (as expected) because it does not take into account geometric projections onto linear space
    2. line mapbox trace
    3. folium

source some points and connected edges

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

  • these are stretched
# 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
    ),
)

enter image description here

plotly mapbox

  • no stretching
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})

enter image description here

folium (using geopandas)

gdf_edges.explore()

enter image description here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!