Permanent markers on plotly text?

I have this code. I’m trying to create a map with the plotly_express markers showing a certain text (from the type column, which is included) right on top of the markers, hence the text = ‘Type’ and textposition = ‘top center’. (See code below.) But when I run the code, the text only appears when I hover, which is the opposite of what I’m looking for. How to fix this issue? To be clear, I specifically want to use px.scatter_mapbox(), not go.scattermapbox() as that’s too complicated for me.

fig = px.scatter_mapbox(
daily_average_exceedances_df,
lat = ‘Latitude’,
lon = ‘Longitude’,
color=‘Daily Exceedances’,
color_continuous_scale=px.colors.sequential.Sunset,
range_color=(0,30),
hover_data=[‘siteId’],
text=daily_average_exceedances_df[‘Type’],
).update_layout(
mapbox={“style”: “carto-positron”, “zoom”:11}, margin={“l”: 0, “r”: 0, “t”: 0, “b”: 0}
)

Thanks,
Buford Bufordson

Is it because I’m missing a mapbox token?

I built a self-contained example (below) from your code, and it seems to work - ‘type’ is always shown, and other things appear on hover. Is that what you’re aiming for?

(Your color coding makes the text difficult to see maybe?)

import plotly.express as px
import plotly.graph_objects as go
import pandas as pd

cities = [dict(name="Aalborg", lat=57.0268172, lon=9.837735, siteId='0', Type='A', daily=1),
          dict(name="Aarhus", lat=56.1780842, lon=10.1119354, siteId='1', Type='A', daily=5),
          dict(name="Copenhagen", lat=55.6712474, lon=12.5237848, siteId='2', Type='B', daily=20)]
df = pd.DataFrame(cities)

fig = px.scatter_mapbox(
    df, lat = 'lat', lon = 'lon',
    hover_data=['siteId'], text=df['Type'],
).update_layout(
    mapbox={'style': 'carto-positron', 'zoom':5,
            'center':go.layout.mapbox.Center(lat=56,lon=10)}, 
    margin={'l': 0, 'r': 0, 't': 0, 'b': 0}
)
fig.show()

Sorry, I don’t see the type above the marker. This is what I see when I run your code. The names of the cities on each marker appear, but I’m not sure if that’s because they’re already on the map. What I’m trying to do is get the type column to appear on top of the map permanently without needing to hover.

image

That’s a mystery - I’m seeing the image here, which does have the type codes.

I guess the first thing is cross-check what versions we’re using - I’m on plotly 5.23.0, python 3.11.2.

I’m using Google Colab: Google Colab

The output on my end is displayed. I think your code works, just not sure why it’s not rendering on my end.

I think Plotly on Colab might have issues - e.g. see

I want the text from the Type column to show up as soon as the map loads, rather than only appearing on hover. I’ve already included the text argument to pull in the Type values, and I set the textposition to 'top center', but it still only shows the text when I hover over the markers. I need to stick with px.scatter_mapbox() because I find it easier to use than go.scattermapbox().