I have a fairly simple goal:
I want to plot a bunch of points on a map of the United States.
When you hover over the point, I want to show some info about it (can do that).
Ideally, if you click on the point, I would like to show more info (is there an example of how to do that?)
For some of these points, I want to connect them with a line (can do that).
But, when I draw the line, it takes over the tool tips, so that all I see are the line data, covering the other tooltip data.
What I would prefer to do is only see data for the line if you hover over the line itself - somewhere between the two ends. And I would like that tooltip to be near the mouse, not at either of the ends.
Hereโs the approach Iโm trying to so far.
Please let me know if there is a better way (I tried line_mapbox with line_group property, but it performs VERY poorly).
The chart with the points:
fig1 = px.scatter_mapbox(
df,
lat = 'latitude',
lon = 'longitude',
color = 'type',
hover_name = 'stuff here',
hover_data = ['anchorBus'],
mapbox_style = 'open-street-map',
height = 900,
color_continuous_scale=px.colors.sequential.Turbo
)
Then I iterate over a dataframe and draw the lines:
for index, row in df.iterrows():
dfFrom = (filter for from)
dfTo = (filter for to)
# get the latitudes and longitudes:
lat_from = dfFrom ['latitude'].values[0]
lon_from = dfFrom ['longitude'].values[0]
lat_to = dfTo ['latitude'].values[0]
lon_to = dfTo ['longitude'].values[0]
fig1.add_trace(
go.Scattermapbox(
mode='lines',
lon=[lon_from, lon_to],
lat=[lat_from, lat_to],
line_color='teal',
name=f'''{row['nameval']}''',
textposition='middle right',
text=f'''ID={row['ID']}''',
showlegend=False,
line=dict(width=4, color='cyan'),
hoverinfo='text',
hoverlabel=dict(
bgcolor='white',
font_size=14,
font_family='Rockwell'
)
)
)