Scatter lat, lon, altitude (3d scatter) on mapbox

Hi,

I try to plot an aircraft route overlaying an open street map, i.e. I have Latitude, Longitude and altitude and would like to do a 3d scatter on top of the mapping object in python.

I have searched for a simple solution but cannot find one. Any advice?

Here is a simple, non-working example.


import plotly.graph_objects as go

lon = [15.3, 15.35, 15.4]
lat = [58.3, 60.7, 64.2]
altitude = [1000, 2000, 3000]  # How do I pass this information to the scatterplot??
fig = go.Figure(go.Scattermapbox(
    mode="markers+lines",
    lon=lon,
    lat=lat,
    marker={'size': 10},
    ),
    )

fig.update_layout(
   margin={'l': 0, 't': 0, 'b': 0, 'r': 0},
   mapbox={
       'style': "open-street-map",
       'center_lat': lat[0],
       'center_lon': lon[0],
       'zoom': 6
       },
    )

Hi @marba751

Just as an Idea consider this comment: you can use scatter3D to plot your points or lines, the put the scattermapbox as background of the plot.

Hi @Bijan ,

Thank you for the response. I tried adding scatter3D, however it creates a new axis on top of the mapbox, thus not a working solution. Do you know if there is a way to override this?

Dear @marba751

Unfortunately I just saw that someone did what I suggested and I don’t know how to do this.

But

I also saw the following plot to air routes in Plotly examples and thought maybe become useful for you.

import plotly.graph_objects as go
import pandas as pd

df_airports = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_us_airport_traffic.csv')
df_airports.head()

df_flight_paths = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_aa_flight_paths.csv')
df_flight_paths.head()

fig = go.Figure()

fig.add_trace(go.Scattergeo(
    locationmode = 'USA-states',
    lon = df_airports['long'],
    lat = df_airports['lat'],
    hoverinfo = 'text',
    text = df_airports['airport'],
    mode = 'markers',
    marker = dict(
        size = 2,
        color = 'rgb(255, 0, 0)',
        line = dict(
            width = 3,
            color = 'rgba(68, 68, 68, 0)'
        )
    )))

flight_paths = []
for i in range(len(df_flight_paths)):
    fig.add_trace(
        go.Scattergeo(
            locationmode = 'USA-states',
            lon = [df_flight_paths['start_lon'][i], df_flight_paths['end_lon'][i]],
            lat = [df_flight_paths['start_lat'][i], df_flight_paths['end_lat'][i]],
            mode = 'lines',
            line = dict(width = 1,color = 'red'),
            opacity = float(df_flight_paths['cnt'][i]) / float(df_flight_paths['cnt'].max()),
        )
    )

fig.update_layout(
    title_text = 'Feb. 2011 American Airline flight paths<br>(Hover for airport names)',
    showlegend = False,
    geo = dict(
        scope = 'north america',
        projection_type = 'azimuthal equal area',
        showland = True,
        landcolor = 'rgb(243, 243, 243)',
        countrycolor = 'rgb(204, 204, 204)',
    ),
)

fig.show()

@marba751 This old plot https://chart-studio.plotly.com/~empet/14375/map-of-france-regions-data-source-1/#/ can suggest how you can create a 3d scatter over a map.
As I can remember, the data for France map have been extracted from a geojson file. The map is drawn on the plane z=0. On xaxis is longitude and on yaxis the latitude of points on the lines retrieved from the geojson file , i.e. you should define:

fig=go.Figure(go.Scatter3d(x=lons, y=lats, z=z, mode.....)
1 Like