✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

Can't hide 'lat' & 'lon' in hover info with px.scatter_mapbox

Hi, I get a NameError when I try to hide lat and lon in the hover info with px.scatter_mapbox. How can I bypass it ?

fig = px.scatter_mapbox(data_frame=gdf,
                        lat=gdf.geometry.y,
                        lon=gdf.geometry.x,
                        size='count',
                        color='type_arret',
                        size_max=20,
                        animation_frame='TRNC_HORR_60',
                        zoom=9,
                        hover_name='nom',
                        hover_template='',
                        hover_data=dict(TRNC_HORR_60=False,
                                    type_arret=False,
                                    count=':.2f',
                                    lon=False,
                                    lat=False)
                       )
NameError: A name conflict was encountered for argument 'lat'. A column or index with name 'lat' is ambiguous.

I’m not trying to be passive aggressive here, but I see no one is responding to my message and I’m wondering if I should report a bug on the GitHub repository instead.

I found the answer myself !
You can use the name of the columns in which the x and y values are located.
When assigning lat and long values, you shouldn’t use gdf.geometry.y nor gdf.geometry.x but do as follows :

gdf['x'] = gdf.geometry.x
gdf['y'] = gdf.geometry.y

fig = px.scatter_mapbox(data_frame=gdf,
                        lat=gdf['y'], #not gdf.geometry.y
                        lon=gdf['x'], #not gdf.geometry.x
                        size='count',
                        color='type_arret',
                        size_max=20,
                        animation_frame='TRNC_HORR_60',
                        zoom=9,
                        hover_name='nom',
                        hover_template='',
                        hover_data=dict(TRNC_HORR_60=False,
                                    type_arret=False,
                                    count=':.2f',
                                    x=False, #not lon=False
                                    y=False) #not lat=False
                       )
1 Like

Hi there, thanks for your post, as I was having the same issue as well.

To make your solution even more clear, the hover data dictionary arguments have to be in the set of dataframe columns you’re passing through in the first argument. So ‘x’ and ‘y’ will not work unless you named your latitude and longitude values x and y respectively.