Plotly Mapbox Text Not Displaying

Hello All! I have some code to plot points of a ship trajectory on plotly express:

 fig = px.scatter_mapbox(df, lat='lat', lon='lon',  
                        zoom=1, mapbox_style="stamen-terrain", 
                        color_continuous_scale='Greys', text="sog")

Where my dataframe contains the columns lat, lon, sog. My goal is to have the ship’s sog at each point displayed as text next to the marker, however when I run this code, not only is there no text, but also the markers no longer display. I am able to hover over the map and see that the points exist, but nothing is visible.

I also tried adding a trace with a mapbox token, but that did not fix the issue.

Could someone help me get the text to display on the map?

Hi @lbracaglia

You would need to specify the type of scale you are using before specifying the color name (Continuous Color Scales and Color Bars | Python | Plotly).

fig = px.scatter_mapbox(df, lat=‘lat’, lon=‘lon’,
zoom=1, mapbox_style=“stamen-terrain”,
color_continuous_scale=px.colors.sequential.Greys, text=“sog”)

Once you are able to rectify this, then you should be able to see both the points as well as the text on your plot.

@sparkmaddy thank you for your advice! Unfortunately I tried your fix and neither the text nor the markers are still visible. The thing is, if I remove the ‘text’ argument, the markers render successfully. Here is a print of my figure if this is more helpful (note that I had to replace some classified data with (xxx):

Figure({
    'data': [{'hovertemplate': (xxx),
              'lat': array([xxx]),
              'legendgroup': 'False',
              'lon': array(xxx),
              'marker': {'color': '#636efa', 'size': 10},
              'mode': 'markers+text',
              'name': 'False',
              'showlegend': True,
              'subplot': 'mapbox',
              'text': array(xxx),
              'type': 'scattermapbox'},
             {'hovertemplate': ('highSpeedNearCoast=True<br>sog' ... '}<br>lon=%{lon}<extra></extra>'),
              'lat': array(xxx),
              'legendgroup': 'True',
              'lon': array(xxx),
              'marker': {'color': '#EF553B', 'size': 10},
              'mode': 'markers+text',
              'name': 'True',
              'showlegend': True,
              'subplot': 'mapbox',
              'text': array(xxx),
              'type': 'scattermapbox'}],
    'layout': {'legend': {'title': {'text': 'xxx'}, 'tracegroupgap': 0},
               'mapbox': {'accesstoken': ('xxx'),
                          'center': {'lat': 23.661944756141075, 'lon': 117.6442023057204},
                          'domain': {'x': [0.0, 1.0], 'y': [0.0, 1.0]},
                          'style': 'stamen-terrain',
                          'zoom': 1},
               'template': '...',
               'title': {'text': 'xxx'}}
})