Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

427
Vistas
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 Respuestas
Responde la pregunta

0

I used the NetworkX and matplotlib.pyplot library.

about 4 years ago · Juan Pablo Isaza Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda